Advertisement
LewisClark

scr_limitDiagonalMotion

Jul 21st, 2017
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// @description scr_limit_diagonal();
  2.  
  3. /// @param maxSpeed The value to cap the speed at.
  4. /// @param timeModifier The modifier value for game time, if none then put 1.
  5.  
  6. // Calculate Angles
  7. var angle = point_direction(0, 0, moveSpeedH, moveSpeedV);
  8. var aa = angle%90;
  9. var b = 90;
  10. var c = 180 - (aa + b);
  11.  
  12. // Calculate Sides
  13. var maxSpeed = argument0;
  14. var timeMod = argument1;
  15.    
  16. // Adjust for movement angle
  17. if(angle < 90 or (angle >= 180 and angle < 270))
  18. {
  19.     var o = dsin(aa)*maxSpeed; // Opposite Side of the Triangle: Our VSP
  20.     var a = dcos(aa)*maxSpeed; // Adjacent Side of the Triangle: Our HSP
  21. }
  22. else
  23. {
  24.     var o = dcos(aa)*maxSpeed; // Opposite Side of the Triangle: Our VSP
  25.     var a = dsin(aa)*maxSpeed; // Adjacent Side of the Triangle: Our HSP
  26. }
  27.    
  28. // Limit Horizontal Speed
  29. moveSpeedH = clamp(moveSpeedH, -a*timeMod, a*timeMod);
  30.    
  31. // Limit Horizontal Speed
  32. moveSpeedV = clamp(moveSpeedV, -o*timeMod, o*timeMod);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement