troll.gd 467 B

12345678910111213141516
  1. extends CharacterBody2D
  2. const MOTION_SPEED = 30
  3. const FRICTION_FACTOR = 0.89
  4. const TAN30DEG = tan(deg_to_rad(30))
  5. func _physics_process(_delta):
  6. var motion = Vector2()
  7. motion.x = Input.get_axis(&"move_left", &"move_right")
  8. motion.y = Input.get_axis(&"move_up", &"move_down")
  9. # Make diagonal movement fit for hexagonal tiles.
  10. motion.y *= TAN30DEG
  11. velocity += motion.normalized() * MOTION_SPEED
  12. # Apply friction.
  13. velocity *= FRICTION_FACTOR
  14. move_and_slide()