playMaker

Author Topic: Can't get consistent jump height at different framerates  (Read 3947 times)

Mupp

  • Full Member
  • ***
  • Posts: 167
Can't get consistent jump height at different framerates
« on: March 15, 2018, 07:24:15 PM »
I'm trying to make a 2d platformer using 3d physics and I can't get jumping to work consistently. As the framerate fluctuate, so does the jump height and I need close to pixel perfect jumps.

The jump should have its height dependent on how long you hold the button. To do this I've tried timing how long you can be in the state with a wait action(real time checked or unchecked), create state loops with next frame event action and neither works for timing.
I also tried launching the player using add force, set velocity or translate. Every combination creates the same problem. I've even tried creating my own gravity and disabled the built in one.

Nothing works so I must have fallen in some trap I don't know about.

So now I could really need some help please on how to create a state that does a jump with a height dependent on how long you hold and jumps exactly the same height regardless if the framerate is 10 or 200.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7614
    • jinxtergames
Re: Can't get consistent jump height at different framerates
« Reply #1 on: March 19, 2018, 06:25:55 PM »
Hi.
I am not sure how you calculate the jump, but maybe the action "Get Time Info" can help.
You can get the time in current state

so when button pressed, go to next state (with that action in it) and on button release go to next state then you will have the time the button was pressed and you can then calculate the jump height


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Can't get consistent jump height at different framerates
« Reply #2 on: March 21, 2018, 12:51:42 PM »
Hi,

 you need to use animation based on time.deltaTime ( action GetTimeInfo), then you get a fps independent animation when you move things around.

 Bye,

 Jean

MarkD

  • Full Member
  • ***
  • Posts: 113
Re: Can't get consistent jump height at different framerates
« Reply #3 on: December 02, 2019, 07:43:45 PM »
I'm having a similar problem and I'm unsure how to use the time.delta time action to fix the issue.

In my project, I want jump height to be the same every time the jump button is pressed.  And, similar to creator of this thread I'm getting different max height values on each jump due to frame rate.

Here's what I'm doing:

State 1:
Curve Float from jumpSpeed (25) to Zero over jumpTime (.15)
Set Velocity to jumpSpeed every frame

We exit that state once the curve float action is complete.

State 2: 
Get Y position of the player for debugging purposes
Wait here for "hang time" (.15)

State 3:
Same as State 1 only curving the float from 0 to jumpSpeed until ground is hit.


Using this, I get a different Y value every time.  Can anyone suggest a way to get a consistent height each time?  I tried using GetTimeInfo/Time.deltaTime but I wasn't clear exactly how that was supposed to help me here.  Maybe I'm just missing something. 

Can anyone point me in the right direction?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Can't get consistent jump height at different framerates
« Reply #4 on: December 03, 2019, 03:24:09 AM »
Hi,

 you need to sample your curve with the delta time as multiplier.

 say you want to animate over 1 second and your curve span over 1 as well.

keep a variable "time",

- set it to 0 at the jump start
- on every update, add delta time to the "time"
- sample the curve at the "time"

this will guarantee a consistent behaviour regardless of the fps.

Bye,

 Jean


MarkD

  • Full Member
  • ***
  • Posts: 113
Re: Can't get consistent jump height at different framerates
« Reply #5 on: December 03, 2019, 02:56:39 PM »
Thanks Jean!

I thought I was following you, but in practice it doesn't seem to be working for me.  Maybe my setup is wrong? 


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Can't get consistent jump height at different framerates
« Reply #6 on: December 04, 2019, 12:44:49 AM »
Hi,

 you need to add the delta time to a variable "time" if you use the raw delta time, it will always be a very small number ( the actual duration of that update frame)

Bye,

 Jean

MarkD

  • Full Member
  • ***
  • Posts: 113
Re: Can't get consistent jump height at different framerates
« Reply #7 on: December 04, 2019, 11:06:00 PM »
That's definitely put me on to the right path, though I'm still having some trouble with aspects of it.  Typing out the issue is hard, so I made a quick video to show you what I'm doing. 


Can you see what I'm doing wrong here?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Can't get consistent jump height at different framerates
« Reply #8 on: December 05, 2019, 12:50:06 AM »
Hi,

 ok, two things:

- your curve float is not setup properly, I missed that in the original post

if your curve is spanning over the right amount of time, don't put anything in time and speed, simply let it run on its own, the action will do that for you. if however you want to constraint the curve over a define duration of say 5 seconds, put 5 in the time value, and it will take 5 seconds for the float to go from start to end values using the curve.

- regardless of the above point, get rid of the delta time action, and tick the box "per second" on the add float action, this will be actually a lot simpler, however for the sake of learning, you could still try to do that manually so that you fully understand the delta time value, ( the per seconds does just that, it multiplies by the delta time).

Let me know how it goes.

Bye,

 Jean


MarkD

  • Full Member
  • ***
  • Posts: 113
Re: Can't get consistent jump height at different framerates
« Reply #9 on: December 05, 2019, 11:16:37 AM »
Hi Jean - thanks for that explanation and I think may have improved things a bit, but I'm still seem to be lost a bit.  I made another video to help explain.  Btw - if there's something more I can show you, please let me know.  Really appreciate your time in helping with this!


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Can't get consistent jump height at different framerates
« Reply #10 on: December 09, 2019, 09:35:20 AM »
Hi,

 I think you are overcomplicating this a lot.

 Your curve should represent the whole jump, including wait time at the apex, etc etc.

also, why not use just physics, controlling velocity with a curve seems counter intuitive to me, give it a push up, and let the physics handle the acceleration deceleration using the physics engine itself. it seems you are trying to force the hand of the physics engine instead of setting up the rigidbody properly and simply use "add force" when you want to jump. This will be far more predictable, fps independent and way easier to tweak.


Also, you need to realize that while PlayMaker editor is open, the performances are all over, because playmaker takes a lot of perfs out, so your game isn't running as it will when published. Try to play without playmaker editor and then open it and see the values.

Bye,

 Jean

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Can't get consistent jump height at different framerates
« Reply #11 on: December 09, 2019, 02:26:18 PM »
Hi,

I work on a 2D platformer as well, and even though my design has nothing to do with hardcore precision platforming, here’s what I learned:

1) Generally apply the jump force with Add Force (2D), because it’s then applied at once and physics takes it from there. This should resolve most inconsistencies.

2) play around with mass, gravity scale and drag in that order. The default behaviour is quite floaty. To get a tighter jump, you need to add more force, but at larger gravity scale working against it. As you will see, these values are totally dependent of one another and need a lot of tuning and testing. This should contribute towards a feel of more precision.

3) to get a really polished jump, you need to add a lot more stuff, not mentioned in typical tutorials. Among them “hang time” which might also contribute towards consistency, i.e. set vertical velocity to 0 for a few frames at peak height.

MarkD

  • Full Member
  • ***
  • Posts: 113
Re: Can't get consistent jump height at different framerates
« Reply #12 on: December 09, 2019, 03:46:52 PM »
Many thanks Thore and Jean!  I'm going to give your suggestions a try and will let you know how it goes.

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Can't get consistent jump height at different framerates
« Reply #13 on: December 09, 2019, 07:58:33 PM »
Another thing that was a major pitfall for me: you have to be super aware with set velocity, and velocity “stored” in an object. Set velocity will override movement that might otherwise be influenced by something else. For example, without input, it can set the velocity to zero if the character is attached to joint, on a platform etc. resulting in odd behaviour. The other situation, that velocity is stored but is not visible, can occur when you change e.g. the rigidbody body type temporarily, or when jumps don’t have a cool down and the forces can stack in a frame for some reason. Things became a ton easier once I monitored the velocity on screen (just via a UI text element). You might also want to cap it to a certain range to prevent freak behaviour. I made an action for this, somewhere in the forum.