Godot 4.4 Stable
I have a few animations that respond to keystrokes in my func _physics_process(delta: float) -> void:
for crouch and jump, but they stop working after the first use. How do I go about fixing this problem? Thank you!
Link to video: https://youtu.be/_gk5EnkCU9o
Physics Process:
func _physics_process(delta: float) -> void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
# Handle Start Jump.
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = JUMP_VELOCITY
anim_tree.set("parameters/Jump/blend_amount", velocity.length() / SPEED)
#Handle Start Crouch
if Input.is_action_pressed("crouch"):
anim_tree.set("parameters/Crouch_Start/blend_amount", 1)
if Input.is_action_just_released("crouch"):
anim_tree.set("parameters/Crouch_End/blend_amount", 1)
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var input_dir := Input.get_vector("left", "right", "forward", "backward")
var direction := (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
direction = direction.rotated(Vector3.UP, spring_arm_pivot.rotation.y)
if direction:
velocity.x = lerp(velocity.x, direction.x * SPEED, lerp_val)
velocity.z = lerp(velocity.z, direction.z * SPEED, lerp_val)
armature.rotation.y = lerp_angle(armature.rotation.y, atan2(-velocity.x, -velocity.z), lerp_val)
else:
velocity.x = lerp(velocity.x, 0.0, lerp_val)
velocity.z = lerp(velocity.z, 0.0, lerp_val)
anim_tree.set("parameters/Run/blend_amount", velocity.length() / SPEED)