tilt.acs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Level tilt handling
  2. int leveltiltpitch, leveltiltangle;
  3. // This is the wrapper script that lets you set the level tilt smoothly
  4. //
  5. // pitch integer - Desired tilt amount in degrees from vertical (so 0 is no tilt)
  6. // angle integer - Desired map angle to tilt along (0 is rotation around y axis, 90 is rotation around x axis)
  7. // speed fixed point - Controls the speed of interpolation (defaults to 5.0)
  8. // override bool - Set to non-zero to force the tilt amount to change immediately instead of being interpolated
  9. //
  10. // The tilt change amount will start out small, and increase as the tilt angle increases
  11. //
  12. script "ChangeTilt" (int pitch, int angle, int speed, int override)
  13. {
  14. if (override || speed == 2147483647) { leveltiltpitch = pitch * 1.0; leveltiltangle = angle * 1.0; Terminate; }
  15. pitch = pitch % 360;
  16. angle = angle % 360;
  17. if (!speed) { speed = 5.0; }
  18. int targetpitch = pitch * 1.0;
  19. int targetangle = angle * 1.0;
  20. int mintiltchange = max(FixedMul(FixedDiv(abs(leveltiltpitch), 180.0), speed), 0.001); // Base max tilt change step amount on starting tilt angle
  21. int tiltspeed;
  22. if (targetpitch > 180.0) { targetpitch -= 360.0; }
  23. else if (targetpitch < -180.0) { targetpitch += 360.0; }
  24. while (
  25. leveltiltpitch - tiltspeed > targetpitch ||
  26. leveltiltpitch + tiltspeed < targetpitch ||
  27. leveltiltangle - 1.0 > targetangle ||
  28. leveltiltangle + 1.0 < targetangle
  29. )
  30. {
  31. if (leveltiltpitch > 180.0) { leveltiltpitch -= 360.0; }
  32. else if (leveltiltpitch < -180.0) { leveltiltpitch += 360.0; }
  33. if (leveltiltangle > 180.0) { leveltiltangle -= 360.0; }
  34. else if (leveltiltangle < -180.0) { leveltiltangle += 360.0; }
  35. tiltspeed = max(FixedMul(FixedDiv(abs(leveltiltpitch), 180.0), speed), mintiltchange); // Tilt faster as you get higher in angle
  36. if (leveltiltpitch - tiltspeed > targetpitch) { leveltiltpitch -= tiltspeed; }
  37. else if (leveltiltpitch + tiltspeed < targetpitch) { leveltiltpitch += tiltspeed; }
  38. if (leveltiltangle - 1.0 > targetangle) { leveltiltangle -= 1.0; }
  39. else if (leveltiltangle + 1.0 < targetangle) { leveltiltangle += 1.0; }
  40. Delay(1);
  41. }
  42. leveltiltpitch = targetpitch;
  43. leveltiltangle = targetangle;
  44. }
  45. // Alternate script to forceably set the tilt amount
  46. script "SetTilt" (int pitch, int angle)
  47. {
  48. ACS_NamedExecute("ChangeTilt", 0, pitch, angle, 2147483647);
  49. }
  50. // The ACS scripts here handle the smooth transitions to new tilt pitch/angles
  51. // The BoATilt item makes the actual changes to the player's view
  52. function void DoTiltEffect(void)
  53. {
  54. SetUserVariable(0, "leveltilt", leveltiltpitch);
  55. SetUserVariable(0, "leveltiltangle", leveltiltangle);
  56. }
  57. script "DoTiltEffect_Wrapper" (void)
  58. {
  59. DoTiltEffect();
  60. }