7 Replies Latest reply on Mar 19, 2010 7:56 PM by Ned Murphy

# Reflecting bullet based on angle of wall

I know this will inolve some trig but how exactly will it be implemented?

Heres what I have for when the bullet hits the wall:

rotation *= -1;

That works based off of gun angle but not wall angle. Any help?

• ###### 1. Re: Reflecting bullet based on angle of wall

Sorry As2

bump

• ###### 3. Re: Reflecting bullet based on angle of wall

If you want the trig solution, you probably want to find a math forum or maybe a gaming tutorial that involves that aspect.  If you tilt the wall, the angle of the rotation is impacted by twice the value of the wall's angle, either adding to or subtracting from depending angle of the wall relative to the perpendicular.  So if the bullet comes in at 45 degrees relative to horizontal, and wall is tilted +10 degrees relative to the vertical, the rotation will be -45 + (2 * 10) = -25 degrees.  If the wall is at -10 degress relative to the vertical under the same bullet condition, the rotation will be -45 + (2 * -10) = -65 degrees.

• ###### 4. Re: Reflecting bullet based on angle of wall

Thanks for the help, It got me some where but not quite there yet. I have this.

var reflect = (this._rotation +(2 * 10));

this._rotation *= reflect;

For some reason no matter what it reflects the bullet straight down at the ground.

-David

• ###### 5. Re: Reflecting bullet based on angle of wall

If coming into the wall you have "this._rotation", then bouncing off the wall you will have...

this.rotation = 2*wall._rotation - this._rotation;

• ###### 6. Re: Reflecting bullet based on angle of wall

Thank you so much, no seriously I was worried I would never find a solution to this problem. It's working now, not perfectly angles are a bit off, but working just fine for now!

• ###### 7. Re: Reflecting bullet based on angle of wall

You're welcome