Smoothly Lower the Player's Max Speed When button is released and Player's Speed is above 200.

  • Hello!

    I'm trying to fix this weird bug in my game and I'm having no luck so far.

    In this game, holding down the Left shoulder gamepad button and moving Left or Right sets your max speed to 300. Normally the value is 200. It also lowers your acceleration and deceleration making the player harder to control, like playing Luigi in Super Mario Bros.

    When the player's speed reaches its maximum point, it sets the Player's Jump Strength to 500 (Normally it's 465) enabling the player to jump higher(This is just for information, it's irrelevant to the problem).

    When the shoulder button is released, a function is called that sets the Player's acceleration and Jump Strength to normal.

    However, I wanted the Player's Max Speed and Deceleration to smoothly transition from the "Running" value to the "Normal" value.

    I tried an event with Every Tick and lerping the Player's Max Speed if the button is not down and the Player's Speed is greater than 200 and it seemed to work at first.

    But, to make this work, I had to disable it when the Player is jumping or falling because it caused other problems.

    That however, makes it possible to stop pressing the shoulder button and keep jumping to retain speed even when the button is not pressed.

    I think the fact that jumping de facto increases the Platform Speed is the core of the problem.

    I've tried many other ways but each one produced its own problems...

    Well, I hope I did an adequate job of explaining this, haha...

    Please ask me if anything is unclear.

    I can't think of any other way to fix this... I'd be grateful for any ideas...

  • I tried an event with Every Tick and lerping the Player's Max Speed if the button is not down and the Player's Speed is greater than 200 and it seemed to work at first.

    But, to make this work, I had to disable it when the Player is jumping or falling because it caused other problems.

    What other problems did it cause?

    Maybe you can decrease the speed slower when the player is in the air and faster when it's on the ground?

    Gamepad Left button is NOT down
    
     Player is on the ground 
     : Player set max speed to lerp(Player.Platform.MaxSpeed, 200, dt*4)
    
     Else : Player set max speed to lerp(Player.Platform.MaxSpeed, 200, dt*1)
    
    
  • Yikes, I forgot to use dt! Gonna check it again now.

    The problem was that the Player changed speed while Jumping, causing some weird "bumps" when jumping even without the button held.

    Also some other method made the Player have almost no momentum while Jumping if his speed was 0.

    Hmm, the classic bug that allows the Player to retain their speed by jumping constantly still happens with your suggestion... )-:

  • I don't understand what bugs are you talking about.. Are you controlling MaxSpeed or speed?

    Here, try this example:

    dropbox.com/s/bts9v6536aj5dc7/PlatformSpeed.capx

  • I don't understand what bugs are you talking about.. Are you controlling MaxSpeed or speed?

    Here, try this example:

    https://www.dropbox.com/s/bts9v6536aj5dc7/PlatformSpeed.capx?dl=0

    By "bug" I meant the original problem I had which allowed the Player to retain high speed by jumping all the time.

    I am controlling Max Speed yes.

    I eventually managed to fix it by using your idea of having different lerp speed values in the air and o the ground (Check the image). Having a 50 * dt value when in the air seems exactly right.

    Hmm, I just checked your capx! Nice and simple! I did not think of using max, maybe max is better performance wise than lerp in this case?

  • Well, I still don't understand why your player can retain high speed by jumping all the time. This doesn't happen in my example.

    Also, dt*50 basically equals 1, and using lerp function with "1" as its third parameter has little sense. Your speed will revert to 200 almost instantly, in 1 or 2 ticks. So you can just set max speed to 200, without any formulas.

    .

    There is a difference between using lerp() like this and subtracting a fixed value every tick. With lerp you get high deceleration in the beginning and slow deceleration in the end. Subtracting is linear. See this example:

    dropbox.com/s/u3ybujq2ssg1yg8/SlowingDownTwoFunctions.capx

    .

    Finally, you shouldn't worry about the performance of math functions, unless you are calling them millions of times every second.

  • Yeah, that was really weird. I wonder if I have a messed up event somewhere. But it now works great with the linear method! I'm really satisfied with the Player physics I've got so far.

    Now to make Ladder/Vine climbing...!

    Oh, dt* 50 is 1? I understand the difference now. Thanks for all the examples, dok2000! You taught me new stuff that'll come handy for sure!

  • dt is the frame duration.

    If your game runs at 60 FPS, dt is approx 0.017s

    So 50*dt=0.83

    .

    At 50 FPS, 50*dt will =1

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I see!

    Thanks for the information!

    Everything works nicely now!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)