Need help with Richochet

Hi, I’ve started creating my first game. Really all I need right now is stuff with richochet. I had some code from a book from Jobe Makar, but it was long and confusing. Here’s the code i’ve got so far, all i need is the actual bouncing of the bullet, at an angle.

if(b.hitTest(CrumblingWall))
//b = the bullet
{
trace(“The bullet hit the wall… Checking for richochet”);
richochetCheck = Math.round(Math.random()*10);
if (richochetCheck >= 5)
{
removeMovieClip(b);
trace(“No richochet”);
}
else
{
trace(“Richochet”);
}

}

Thx guys, :hitman2:

What angle do you want it to bounce at? Is the bullet coming in at an angle?

It will almost always come in at an angle. The bullet is a circle and the object being hit is a rectangle.

So do you want it to bounce off on a random angle, or based on the angle it came in on?

based on the angle it came in on would be good.

I’ll work on it if i have any spare time and get back to you, mostly because I could use the code myself :slight_smile:

Lol. Ok, thx Nich. There’s another little problem if you’d be willing to help out. The bullets simply won’t make more than one at a time. As in if I fire it will move well enough but if i fire again that last bullet shot dissapears and another one appears at the tip of my gun. Except when I die, It shouldn’t let me shoot, but when it does it works right. It’s very strange.

onMouseDown = function () {
var b = attachMovie(“bullet”, “bullet”+depth, depth++);
b._x=MainHero._x, b._y=MainHero._y;
b._t = Math.atan2(this._ymouse-b._y, this._xmouse-b._x);
b.onEnterFrame = function() {
this._x += Math.cos(this._t)*9;
this._y += Math.sin(this._t)*9;

Make depth++ -> depth, then add depth++ after.

var b = attachMovie(“bullet”, “bullet”+depth, depth);
depth++;

That doesn’t help any. Is it a problem with depth?