func update(input: InputPacket, delta: float):
+ player.velocity = get_new_velocity_from_input(input, delta)
+ player.move_and_slide()
+
+
+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 move_direction := (
+ var movement_direction := (
forward * input.movement_direction.y + right * input.movement_direction.x
).normalized()
- move_direction.y = 0
+ 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
- var floor_normal = player.get_floor_normal()
- var ground_slope_input = (PI / 2) - player.velocity.angle_to(floor_normal)
- player.velocity = player.velocity.move_toward(
- move_direction * (player.walk_speed + ground_slope_input * player.walk_speed),
+ 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
)
-
- player.move_and_slide()
+
+ return new_velocity