12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- // Level tilt handling
- int leveltiltpitch, leveltiltangle;
- // This is the wrapper script that lets you set the level tilt smoothly
- //
- // pitch integer - Desired tilt amount in degrees from vertical (so 0 is no tilt)
- // angle integer - Desired map angle to tilt along (0 is rotation around y axis, 90 is rotation around x axis)
- // speed fixed point - Controls the speed of interpolation (defaults to 5.0)
- // override bool - Set to non-zero to force the tilt amount to change immediately instead of being interpolated
- //
- // The tilt change amount will start out small, and increase as the tilt angle increases
- //
- script "ChangeTilt" (int pitch, int angle, int speed, int override)
- {
- if (override || speed == 2147483647) { leveltiltpitch = pitch * 1.0; leveltiltangle = angle * 1.0; Terminate; }
- pitch = pitch % 360;
- angle = angle % 360;
- if (!speed) { speed = 5.0; }
- int targetpitch = pitch * 1.0;
- int targetangle = angle * 1.0;
- int mintiltchange = max(FixedMul(FixedDiv(abs(leveltiltpitch), 180.0), speed), 0.001); // Base max tilt change step amount on starting tilt angle
- int tiltspeed;
- if (targetpitch > 180.0) { targetpitch -= 360.0; }
- else if (targetpitch < -180.0) { targetpitch += 360.0; }
- while (
- leveltiltpitch - tiltspeed > targetpitch ||
- leveltiltpitch + tiltspeed < targetpitch ||
- leveltiltangle - 1.0 > targetangle ||
- leveltiltangle + 1.0 < targetangle
- )
- {
- if (leveltiltpitch > 180.0) { leveltiltpitch -= 360.0; }
- else if (leveltiltpitch < -180.0) { leveltiltpitch += 360.0; }
- if (leveltiltangle > 180.0) { leveltiltangle -= 360.0; }
- else if (leveltiltangle < -180.0) { leveltiltangle += 360.0; }
- tiltspeed = max(FixedMul(FixedDiv(abs(leveltiltpitch), 180.0), speed), mintiltchange); // Tilt faster as you get higher in angle
- if (leveltiltpitch - tiltspeed > targetpitch) { leveltiltpitch -= tiltspeed; }
- else if (leveltiltpitch + tiltspeed < targetpitch) { leveltiltpitch += tiltspeed; }
- if (leveltiltangle - 1.0 > targetangle) { leveltiltangle -= 1.0; }
- else if (leveltiltangle + 1.0 < targetangle) { leveltiltangle += 1.0; }
- Delay(1);
- }
- leveltiltpitch = targetpitch;
- leveltiltangle = targetangle;
- }
- // Alternate script to forceably set the tilt amount
- script "SetTilt" (int pitch, int angle)
- {
- ACS_NamedExecute("ChangeTilt", 0, pitch, angle, 2147483647);
- }
- // The ACS scripts here handle the smooth transitions to new tilt pitch/angles
- // The BoATilt item makes the actual changes to the player's view
- function void DoTiltEffect(void)
- {
- SetUserVariable(0, "leveltilt", leveltiltpitch);
- SetUserVariable(0, "leveltiltangle", leveltiltangle);
- }
- script "DoTiltEffect_Wrapper" (void)
- {
- DoTiltEffect();
- }
|