Untitled
unknown
plain_text
a year ago
1.9 kB
9
Indexable
func _physics_process(delta):
# Handle functions
handle_controls(delta)
handle_gravity(delta)
# Movement
var applied_velocity: Vector3
# Calculate movement_velocity based on input
var input_direction = Vector3(Input.get_vector("move_left", "move_right", "move_forward", "move_back"), 0, 0).normalized()
movement_velocity = input_direction * movement_speed
# Apply knockback velocity
applied_velocity = movement_velocity + knockback_velocity
# Decay the knockback velocity over time
knockback_velocity = knockback_velocity.move_toward(Vector3.ZERO, knockback_decay_rate * delta)
# Apply the final velocity
applied_velocity.y = -gravity
velocity = velocity.lerp(applied_velocity, delta * 10)
move_and_slide()
# Rotation (unchanged)
camera.rotation.z = lerp_angle(camera.rotation.z, -input_mouse.x * 25 * delta, delta * 5)
camera.rotation.x = lerp_angle(camera.rotation.x, rotation_target.x, delta * 25)
rotation.y = lerp_angle(rotation.y, rotation_target.y, delta * 25)
container.position = lerp(container.position, container_offset - (basis.inverse() * applied_velocity / 30), delta * 10)
# Movement sound (unchanged)
sound_footsteps.stream_paused = true
if is_on_floor():
if abs(velocity.x) > 1 or abs(velocity.z) > 1:
sound_footsteps.stream_paused = false
# Landing after jump or falling (unchanged)
camera.position.y = lerp(camera.position.y, 0.0, delta * 5)
if is_on_floor() and gravity > 1 and !previously_floored: # Landed
Audio.play("sounds/land.ogg")
camera.position.y = -0.1
previously_floored = is_on_floor()
# Falling/respawning (unchanged)
if position.y < -10:
get_tree().reload_current_scene()
Editor is loading...
Leave a Comment