player.gd 503 B

12345678910111213141516171819202122
  1. extends CharacterBody3D
  2. # Moves the player
  3. @export_range(1, 2) var player_id: int = 1
  4. @export var walk_speed: float = 2
  5. func _physics_process(_delta):
  6. var move_direction = Input.get_vector(
  7. "move_left_player" + str(player_id),
  8. "move_right_player" + str(player_id),
  9. "move_up_player" + str(player_id),
  10. "move_down_player" + str(player_id),
  11. )
  12. velocity.x += move_direction.x * walk_speed
  13. velocity.z += move_direction.y * walk_speed
  14. # Apply friction.
  15. velocity *= 0.9
  16. move_and_slide()