Advertisement
Guest User

Code

a guest
Oct 25th, 2020
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. extends KinematicBody
  2.  
  3. var speed = 250
  4. var direction = Vector3()
  5. var gravity = -9.8
  6. var velocity = Vector3()
  7.  
  8. func _ready():
  9. pass
  10.  
  11. func _physics_process(delta):
  12. direction = Vector3(0,0,0)
  13. if Input.is_action_pressed("ui_left"):
  14. direction.x -= 1
  15. if Input.is_action_pressed("ui_right"):
  16. direction.x += 1
  17. if Input.is_action_pressed("ui_up"):
  18. direction.z -= 1
  19. if Input.is_action_pressed("ui_down"):
  20. direction.z += 1
  21. direction = direction.normalized()
  22. direction = direction * speed * delta
  23.  
  24. if velocity.y > 0:
  25. gravity = -20
  26. else:
  27. gravity = -30
  28.  
  29. velocity.y += gravity * delta
  30. velocity.x = direction.x
  31. velocity.z = direction.z
  32.  
  33. velocity = move_and_slide(velocity, Vector3(0,1,0))
  34.  
  35. if is_on_floor() and Input.is_key_pressed(KEY_SPACE):
  36. velocity.y = 5
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement