- Joined
- Mar 1, 2013
- Messages
- 555
Hi.
I want a projectile to bounce when it collides with a cliff. I got the angle right but I struggle to set the correct x-velocity and y-velocity from that angle.
• What I gave
• What I want
• What I got
I believe that the problem occurs from where I calculate xyz_Vel (Total Velocity)
________________________________________________________________
Solved
I used the Sign function when setting the xyz_YVel[] instead of the Sin function.
I want a projectile to bounce when it collides with a cliff. I got the angle right but I struggle to set the correct x-velocity and y-velocity from that angle.
• What I gave
• What I want
• What I got

I believe that the problem occurs from where I calculate xyz_Vel (Total Velocity)
-
Reflect
-
Events
-
Conditions
-
Actions
-
-------- Current Direction --------
-
Custom script: set udg_xyz_Angle = bj_RADTODEG * Atan2(udg_xyz_YVel[udg_xyz_Ref], udg_xyz_XVel[udg_xyz_Ref])
-
Game - Display to (All players) the text: (In: + (String(xyz_Angle)))
-
-------- Wall angle is the facing angle of the cliff --------
-
Game - Display to (All players) the text: (Wall: + (String(xyz_WallAngle)))
-
-------- Reflected Direction --------
-
Set xyz_Angle = ((2.00 x xyz_WallAngle) - (xyz_Angle + 180.00))
-
Game - Display to (All players) the text: (Out: + (String(xyz_Angle)))
-
-------- Total Velocity --------
-
Set xyz_Vel = (Square root(((xyz_XVel[xyz_Ref] x xyz_XVel[xyz_Ref]) + (xyz_YVel[xyz_Ref] x xyz_YVel[xyz_Ref]))))
-
-------- X/Y Velocity --------
-
Set xyz_XVel[xyz_Ref] = (xyz_Vel x (Cos(xyz_Angle)))
-
Set xyz_YVel[xyz_Ref] = (xyz_Vel x (Sign(xyz_Angle)))
-
Custom script: call SetUnitX(udg_UDexUnits[udg_xyz_Ref],udg_xyz_XCur + udg_xyz_XVel[udg_xyz_Ref])
-
Custom script: call SetUnitY(udg_UDexUnits[udg_xyz_Ref],udg_xyz_YCur + udg_xyz_YVel[udg_xyz_Ref])
-
-
________________________________________________________________
Solved
I used the Sign function when setting the xyz_YVel[] instead of the Sin function.
Last edited: