• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] Angles

Status
Not open for further replies.
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
94dda527b5.png



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])
Help will be appreciated.

________________________________________________________________


Solved
I used the Sign function when setting the xyz_YVel[] instead of the Sin function.
 
Last edited:
Status
Not open for further replies.
Top