# Need help with Richochet

**URL:** https://forum.kirupa.com/t/need-help-with-richochet/184266
**Category:** programming
**Created:** [April 3, 2006, 9:44pm UTC](https://forum.kirupa.com/t/need-help-with-richochet/184266 "2006-04-03T21:44:58Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![woad](https://avatars.discourse-cdn.com/v4/letter/w/34f0e0/32.png) [@woad](https://forum.kirupa.com/u/woad)
#### Post date: [April 3, 2006, 9:44pm UTC](https://forum.kirupa.com/t/need-help-with-richochet/184266/1 "2006-04-03T21:44:58Z")

</div>

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:

---

<div class="post-metadata">

### Author: ![Nich](https://avatars.discourse-cdn.com/v4/letter/n/e79b87/32.png) [@Nich](https://forum.kirupa.com/u/Nich)
#### Post date: [April 3, 2006, 10:49pm UTC](https://forum.kirupa.com/t/need-help-with-richochet/184266/2 "2006-04-03T22:49:25Z")

</div>

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

---

<div class="post-metadata">

### Author: ![woad](https://avatars.discourse-cdn.com/v4/letter/w/34f0e0/32.png) [@woad](https://forum.kirupa.com/u/woad)
#### Post date: [April 3, 2006, 10:57pm UTC](https://forum.kirupa.com/t/need-help-with-richochet/184266/3 "2006-04-03T22:57:52Z")

</div>

> [@Nich](#):
>
> 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.

---

<div class="post-metadata">

### Author: ![Nich](https://avatars.discourse-cdn.com/v4/letter/n/e79b87/32.png) [@Nich](https://forum.kirupa.com/u/Nich)
#### Post date: [April 3, 2006, 11:08pm UTC](https://forum.kirupa.com/t/need-help-with-richochet/184266/4 "2006-04-03T23:08:36Z")

</div>

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

---

<div class="post-metadata">

### Author: ![woad](https://avatars.discourse-cdn.com/v4/letter/w/34f0e0/32.png) [@woad](https://forum.kirupa.com/u/woad)
#### Post date: [April 3, 2006, 11:11pm UTC](https://forum.kirupa.com/t/need-help-with-richochet/184266/5 "2006-04-03T23:11:35Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Nich](https://avatars.discourse-cdn.com/v4/letter/n/e79b87/32.png) [@Nich](https://forum.kirupa.com/u/Nich)
#### Post date: [April 4, 2006, 12:46am UTC](https://forum.kirupa.com/t/need-help-with-richochet/184266/6 "2006-04-04T00:46:49Z")

</div>

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

---

<div class="post-metadata">

### Author: ![woad](https://avatars.discourse-cdn.com/v4/letter/w/34f0e0/32.png) [@woad](https://forum.kirupa.com/u/woad)
#### Post date: [April 4, 2006, 12:51am UTC](https://forum.kirupa.com/t/need-help-with-richochet/184266/7 "2006-04-04T00:51:23Z")

</div>

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;

---

<div class="post-metadata">

### Author: ![Nich](https://avatars.discourse-cdn.com/v4/letter/n/e79b87/32.png) [@Nich](https://forum.kirupa.com/u/Nich)
#### Post date: [April 4, 2006, 2:28am UTC](https://forum.kirupa.com/t/need-help-with-richochet/184266/8 "2006-04-04T02:28:23Z")

</div>

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

---

<div class="post-metadata">

### Author: ![woad](https://avatars.discourse-cdn.com/v4/letter/w/34f0e0/32.png) [@woad](https://forum.kirupa.com/u/woad)
#### Post date: [April 4, 2006, 2:34am UTC](https://forum.kirupa.com/t/need-help-with-richochet/184266/9 "2006-04-04T02:34:51Z")

</div>

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

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