Godot Version
Godot Engine v4.3
Question
I have a CharacterBody3d that I want to jump the moment that it detects that it’s collided with the floor. I want the jump force to be added to the ‘real’ y velocity so the player gets less height when walking down a slope and more height if they’re walking up a slope. Here’s a stripped down version of what I’m trying to add:
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity") # 22
var wish_jump: bool = false
var last_y_vel: float
func _physics_process(delta: float) -> void:
var vel: Vector3 = get_velocity()
queue_jump() # sets wish_jump
if is_on_floor() and last_y_vel != 0: # show last y velocity after hitting floor
print(last_y_vel)
if is_on_floor():
if wish_jump:
wish_jump = false
vel.y += jump_force #+ last_y_vel
else:
vel.y = 0
else: # in the air
vel.y -= gravity * delta
velocity = vel
move_and_slide()
last_y_vel = get_real_velocity().y
I was hoping that the moment that the player touches the floor in this case, their y velocity during the physics tick should be zero.
In reality, when is_on_floor()
returns true, the previous call to get_real_velocity()
returns -5.31, 0.30, 0.03
for each subsequent call of the physics process. I can’t tell if get_real_velocity()
returns the difference of how far the player traveled last move, or the vector of the remaining motion, or something else that I’m not understanding.
I’m new to pretty much all of this, so I’m unsure if I’m not using the method correctly or missing some other way to go about solving my problem, so any help would be greatly appreciated!