PlayerMovement.gd 543 B

1234567891011121314151617
  1. extends KinematicBody
  2. # Moves the player
  3. export(int, 1, 2) var player_id = 1
  4. export(float) var walk_speed = 20.0
  5. func _physics_process(_delta):
  6. var velocity = Vector3.ZERO
  7. velocity.z = -Input.get_action_strength("move_up_player" + str(player_id))
  8. velocity.z += Input.get_action_strength("move_down_player" + str(player_id))
  9. velocity.x = -Input.get_action_strength("move_left_player" + str(player_id))
  10. velocity.x += Input.get_action_strength("move_right_player" + str(player_id))
  11. move_and_slide(velocity.normalized() * walk_speed)