Advertisement
Guest User

Untitled

a guest
Nov 10th, 2018
13,019
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. extends KinematicBody
  2.  
  3. const MOVE_SPEED = 4
  4. const MOUSE_SENS = 0.5
  5.  
  6. onready var anim_player = $AnimationPlayer
  7. onready var raycast = $RayCast
  8.  
  9. func _ready():
  10. Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
  11. yield(get_tree(), "idle_frame")
  12. get_tree().call_group("zombies", "set_player", self)
  13.  
  14. func _input(event):
  15. if event is InputEventMouseMotion:
  16. rotation_degrees.y -= MOUSE_SENS * event.relative.x
  17.  
  18. func _process(delta):
  19. if Input.is_action_pressed("exit"):
  20. get_tree().quit()
  21. if Input.is_action_pressed("restart"):
  22. kill()
  23.  
  24. func _physics_process(delta):
  25. var move_vec = Vector3()
  26. if Input.is_action_pressed("move_forwards"):
  27. move_vec.z -= 1
  28. if Input.is_action_pressed("move_backwards"):
  29. move_vec.z += 1
  30. if Input.is_action_pressed("move_left"):
  31. move_vec.x -= 1
  32. if Input.is_action_pressed("move_right"):
  33. move_vec.x += 1
  34. move_vec = move_vec.normalized()
  35. move_vec = move_vec.rotated(Vector3(0, 1, 0), rotation.y)
  36. move_and_collide(move_vec * MOVE_SPEED * delta)
  37.  
  38. if Input.is_action_pressed("shoot") and !anim_player.is_playing():
  39. anim_player.play("shoot")
  40. var coll = raycast.get_collider()
  41. if raycast.is_colliding() and coll.has_method("kill"):
  42. coll.kill()
  43.  
  44. func kill():
  45. get_tree().reload_current_scene()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement