Delta time fix?

Okay here’s proof that i’m not flying like a bird.

GIF_20250930_152601_992

I’m mashing it as fast as I can.

(And sorry for the zooming :laughing:. I made a mistake in the GIF. And this GIF looks slow because I had to make the file small.)

I don’t know what I did to stop jumping infinitely like yours, but I think I fixed it somewhere in the player code. Just not in the jump code.

Then I’m really curious about what values you use, especially for the timer duration. :thinking:

1 Like

My jumpbuffer is 0.25.
My jump velociy is -300.

Not sure if this is related to the post though. :laughing:

Off topic too…

Is making a node-based state machine messy and hard to scroll through the states? Because i’m not sure if I want just 1 node to control states and be the state machine…

A too short jumpbuffer could have caused at least inconsistent jump heights (because every jump would be either very short or very high, without in-betweens). 0.25 is more then enough to rule that out though.

And about the state machine, I’d say a node based state machine probably is a good way to learn keeping your code organized and structured. Because it’s easier to achieve that in a node-based one, but more important as well.

1 Like

Interesting..

So do I make my jumpbuffer time to .1 instead of .25?

No, I meant to say 0.25 is fine. A lower value would probably just make the varying jump height feel weird.

1 Like

So is that why I am jumping higher with lower fps?

Imagine there’s 2 frames per second, so the delta (time between the last frame and now) will be 1sec / 2frames = 0.5sec/frame. Then, you do x += 100 * delta, and you discovered that 100 was being added in total per second!

Multiply delta to things that were continuously applying throughout frames, and DO NOT multiply when it’s just an instant effect.

1 Like

No, this isn’t related. And I honestly have no idea what could cause that here.

If you were talking about different physics tick rates I had an idea, though I’m not sure if the effect would be noticeable at all. But that isn’t affected by changing the max fps anyway.

1 Like

So which line do I change to * delta?

I.m.o it does not make much sense to spend a lot of time looking for a solution. All of the jumping-logic looks kind of sketchy to me. It would probably be better and take less time to rewrite it from scratch.

1 Like

To be fair… yes I was thinking of removing everything and making a state machine. But i’m scared of errors and etc… so not sure if I should.

Your jump is an instant velocity change, which should set velocity.y = JUMP_VELOCITY.

1 Like

I think it could better to focus on the small easy things first until you become more comfortable. There is no reason to add another thing to get confused by, if you are already struggling with a lot of other things. You will have more fun and learn faster if you try to learn one or a few things at the time at most.

1 Like

I think you might benefit from a programming technique called rubber-ducking. It’s when you explain your code to someone else and often figure out the solution during the explanation.

This is the default jump code for CharacterBody2D:

const JUMP_VELOCITY = -400.0
.
.
.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
	velocity.y = JUMP_VELOCITY

How did you get from that, to the code you have now?

2 Likes

The PhyscicsController looks pretty cool. Do you have a link to the video?

Just this weekend, I was working on a jump state based on this talk, and some code that a Zenva lesson had derived from it.

The problem I was encountering is they derive gravity and apply it to the character to work - and as of 4.4.1, there is a get_gravity() function. This function is great, because it applies gravity from Area2D (or Ares3D) nodes, allowing you to override gravity in certain areas easily. But that means you have to deal with it in a different way.

This is the way I came up with this past weekend. By tweaking the jump_velocity on my jump state and the fall_gravity_multiplier on my fall state, I can control how fast and high the player jumps, and how fast it falls,

## Applies gravity to the character. The gravity multiplier can be used when jumping or falling
## to make the character rise slower or faster, or to fall like a rock or a feather.
## This function uses get_gravity() so that it is affected by Area3D nodes that
## might also apply a localized gravity.
func apply_gravity(delta: float, gravity_multiplier: float = 1.0) -> void:
	velocity += get_gravity() * delta * gravity_multiplier
1 Like

I mixed up tutorials with my jump code. (Yes I suck.)

So do I remove all code and restart? Because it’s messy and ugly? I’m not familliar with coding and game dev too much, so i’m kinda confused.

I also made my game ugly (on purpose.) so that I wouldn’t get distracted by the art because the art makes me feel like improving the art instead of the code and etc. what matters is how fun it is and the code, (From what I learned.) So I would remove all animation related code.

Edit: Actually I think I will stop this post because my code is ugly. So since the code’s gonna change, there’s no point in helping this code. (Thank u everyone though for the info and etc! Pls don’t reply to this post to make it dead.)

1 Like