# when using move_and_slide is it correct to use delta for accelleration

Attention Topic was automatically imported from the old Question2Answer platform.

Hi everybody,

When applying gravity and horizontal acceleration I’m using delta even tough I know that move_and_slide multiplies delta to the velocity.

But to me it didn’t made sense, mathematically speaking to to add a velocity (S/T) to an accelleration (S/T^2) so that’s why I’m multiplying by delta:

``````   func get_player_x_velocity(delta: float, direction: float, current_x_velocity: float) -> float:
if direction == 0 and abs(current_x_velocity) > 0:
var deceleration_rate: = GROUND_DECELERATION_RATE if is_on_floor() else AIR_DECELERATION_RATE
return lerp(current_x_velocity, 0, deceleration_rate)
var next_x_velocity: = abs(current_x_velocity) + (H_ACCELLERATION * delta)
next_x_velocity = sign(direction) * min(next_x_velocity, MAX_H_VELOCITY)
return next_x_velocity

func get_player_y_velocity(delta: float, current_y_velocity: float) -> float:
var is_jump_button_pressed: = Input.is_action_just_pressed("jump")
var is_jump_button_released: = Input.is_action_just_released("jump")
if is_on_floor() and is_jump_button_pressed:
return current_y_velocity + JUMP_STRENGTH + (GRAV * delta)
if current_y_velocity < 0 and is_jump_button_released:
return 0.0
return current_y_velocity + (GRAV * delta)
``````

You are correct. Your acceleration should be multiplied by `delta` when you add it to velocity. You then pass that velocity to `move_and_slide()` and then it multiplies velocity by `delta` to get a distance. If you weren’t using `move_and_slide()` you’d multiply velocity by `delta` yourself.

Great this is what I thought, but I was not 100% sure

Pitagoric | 2021-02-11 05:47

this still doesn’t make sense to me. in the following official example we have an acceleration on x, which doesn’t multiply by delta, and an acceleration on y (gravity) which does: Physics introduction — Godot Engine (latest) documentation in English

why the one and not the other?

Update: I want to instantly correct myself, because i realized you can actually test this by changing the Physics Fps in Project Setting, and the jump height changes with different Fps.

So all good.

If i understand it correctly now, whenever you add velocities manually in code you have to use delta, right?

k3nzngtn | 2022-06-28 14:57

There’s no acceleration in the x direction in that example.

It’s not about velocities specifically, it’s things that are per unit time. If a quantity is time-dependent, then you should factor in time.

kidscancode | 2022-06-28 16:55