troll.gd 979 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. extends KinematicBody2D
  2. # This is a simple collision demo showing how
  3. # the kinematic cotroller works.
  4. # move() will allow to move the node, and will
  5. # always move it to a non-colliding spot,
  6. # as long as it starts from a non-colliding spot too.
  7. #pixels / second
  8. const MOTION_SPEED=160
  9. func _fixed_process(delta):
  10. var motion = Vector2()
  11. if (Input.is_action_pressed("move_up")):
  12. motion+=Vector2(0,-1)
  13. if (Input.is_action_pressed("move_bottom")):
  14. motion+=Vector2(0,1)
  15. if (Input.is_action_pressed("move_left")):
  16. motion+=Vector2(-1,0)
  17. if (Input.is_action_pressed("move_right")):
  18. motion+=Vector2(1,0)
  19. motion = motion.normalized() * MOTION_SPEED * delta
  20. motion = move(motion)
  21. #make character slide nicely through the world
  22. var slide_attempts = 4
  23. while(is_colliding() and slide_attempts>0):
  24. motion = get_collision_normal().slide(motion)
  25. motion=move(motion)
  26. slide_attempts-=1
  27. func _ready():
  28. # Initalization here
  29. set_fixed_process(true)
  30. pass