Momentum gain

Version:

4.0

Added on:

26 Aug 2019 13:51

Tags:

Description:
This simple script changes the running mechanics. Instead of simply holding a button in order to achieve greater movement velocity, you now have to build up enough momentum in order to be able to run. This can be accomplished in two ways - either by holding a movement key for a long enough duration (two seconds to be exact), or by gaining speed via some kind of enabling feature, for example a horizontal spring or pole. You lose your momentum if you release the movement key, change direction or bump into something.

EDIT: Minor improvement.

EDIT 2: Enabled intermediate running speeds between jogging and sprinting.
  1. int warmupTime = 0;
  2.  
  3. void onPlayerInput(jjPLAYER@ play) {
  4.   if ((play.keyLeft == true || play.keyRight == true) && play.xSpeed != 0) {
  5.     warmupTime++;
  6.   } else {
  7.     warmupTime = 0;
  8.   }
  9.  
  10.   if ((play.keyLeft == true && play.direction == 1) || (play.keyRight == true && play.direction == -1)) {
  11.     warmupTime = 0;
  12.   }
  13.  
  14.   if (warmupTime >= 35 || play.xSpeed > 8 || play.xSpeed < -8) {
  15.     play.keyRun = true;
  16.     if (warmupTime > 0 && warmupTime < 105 && play.xSpeed > -8 && play.xSpeed < 8) {
  17.       play.xSpeed = play.xSpeed * 0.95;
  18.     }
  19.   } else {
  20.     play.keyRun = false;
  21.   }
  22. }