# Reflect Angle

### » Sat Jan 01, 2011 1:47 pm

How can I go about doing a reflect angle? I'm not using any Behaviors, just the standard X/Y static engine.

XSpeed: Player.X+Player('XSpeed')
YSpeed: Player.Y+Player('YSpeed')

I already have the angel velocity.

Value = 1

XSpeed: 12*Cos(Angle)
YSpeed: -12*Sin(Angle)

I just need to get a proper Reflect angle collision.
B
11
S
3
G
8
Posts: 473
Reputation: 4,569

### » Sat Jan 01, 2011 8:23 pm

You just need the angle of the wall to reflect off of, thin sprites work well for that.
[code:357lq604]+ Player: On collision between Player and wall
-> Player: Set angle to 2*wall.Angle - Player.Angle[/code:357lq604]
B
100
S
38
G
134
Posts: 5,556
Reputation: 85,325

### » Sat Jan 01, 2011 9:54 pm

Well, I kind of need it to reflect of the Object current angle. It works like Pulseman's Voltecer

I would need to reflect not just floors but walls. Not to mention that all the floor tiles would be at 0.

If the object his the at floor 225, it would reflect to 135. If ita celiling at 135, it would reflect to 225.

Doing something like this.
B
11
S
3
G
8
Posts: 473
Reputation: 4,569

### » Sat Jan 01, 2011 10:52 pm

Set angle to "2*wall.Angle - Player.Angle" does reflect the objects angle. Another way is using overlapping at offset to see if there's a wall horizontal or vertical from the object and just reversing the sign for either the x velocity or y velocity.

Here's an example with both methods:
B
100
S
38
G
134
Posts: 5,556
Reputation: 85,325

### » Sun Jan 02, 2011 8:54 pm

Worked, awesome.

By the way, do you how to set angle based on on X/Y Velocity?
B
11
S
3
G
8
Posts: 473
Reputation: 4,569

### » Sun Jan 02, 2011 9:33 pm

[quote="Azu":2i36jxsb]By the way, do you how to set angle based on on X/Y Velocity?[/quote:2i36jxsb]
Basically, if the velocity is expressed both negative and positive, then the angle of the velocity at that moment of time you sample it is
angle(0, 0, xVel, yVel)

But you would need to take into account the current angle of the object, the velocity is applied to. When time based it could be something like that:
object.angle = object.angle + angle(0, 0, xVel, yVel) * TimeDelta

(If I'm not totally off beam)

EDIT: Ah, sorry, no, the last one is not correct. It would spin the object even if the angle is already reached.
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,289

### » Sat Jan 08, 2011 3:08 am

How would I get this "2*wall.Angle - Player.Angle" to work with X/Y Velocity?
B
11
S
3
G
8
Posts: 473
Reputation: 4,569

### » Sat Jan 08, 2011 11:29 am

[quote:2cyb294m]How would I get this "2*wall.Angle - Player.Angle" to work with X/Y Velocity?[/quote:2cyb294m]
First convert X/Y Velocity into an angle and distance:
angle_of_motion = angle(0, 0, X_Velocity, Y_Velocity)
speed_of_motion = distance(0, 0, X_Velocity, Y_Velocity)

Next Find the bounce angle:
new_angle_of_motion = 2*wall.Angle - angle_of_motion

And then convert back to x/y:
X_Velocity = speed_of_motion * cos(new_angle_of_motion)
Y_Velocity = speed_of_motion * sin(new_angle_of_motion)
B
100
S
38
G
134
Posts: 5,556
Reputation: 85,325