Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Pitagoric |
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)