extends Move class_name Walk const skin_lean_limit := PI/4 func update(input: InputPacket, delta: float): player.velocity = get_new_velocity_from_input(input, delta) player.move_and_slide() # update skin rotation var skin_target_angle := Vector3.BACK.signed_angle_to( player.last_movement_direction, Vector3.UP ) player.skin.global_rotation.y = lerp_angle( player.skin.global_rotation.y, skin_target_angle, player.rotation_speed * delta ) # lean into player momentum just a little bit player.skin.rotation.z = lerp_angle( player.skin.rotation.z, clamp( player.last_movement_direction.signed_angle_to( player.velocity, Vector3.UP ) * player.velocity.length() * 0.08, -skin_lean_limit, skin_lean_limit ), player.rotation_speed * delta * 0.25 ) func get_new_velocity_from_input(input: InputPacket, delta: float) -> Vector3: # Get the XZ input direction based on player's input relative to the camera var forward := camera.global_basis.z var right := camera.global_basis.x var movement_direction := ( forward * input.movement_direction.y + right * input.movement_direction.x ).normalized() movement_direction.y = 0 # save off last movement direction if movement_direction.length() > 0.2: player.last_movement_direction = movement_direction # if we're not stuck, then it's okay to set the velocity player.floor_normal = player.get_floor_normal() player.ground_slope_input = (PI / 2) - player.velocity.angle_to(player.floor_normal) var new_velocity = player.velocity.move_toward( movement_direction * (player.walk_speed + player.ground_slope_input * player.walk_speed), player.acceleration * delta ) return new_velocity