Advertisement
chris33556

basic_move_and_jump-script

Aug 21st, 2022
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. extends KinematicBody
  2.  
  3. onready var animatedSprite = $AnimatedSprite3D
  4. var velocity = Vector3()
  5. export var speed = 10
  6. export var gravity = 30
  7. export var jump = 30
  8.  
  9.  
  10.  
  11.  
  12.  
  13. func _process(delta):
  14. _gravity(delta)
  15. _jumpforce()
  16. var input_vector = Vector3.ZERO
  17. input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
  18. input_vector.z = Input.get_action_strength("ui_up") - Input.get_action_strength("ui_down")
  19. input_vector = input_vector.normalized()
  20.  
  21. if input_vector != Vector3.ZERO:
  22. velocity.x = input_vector.x * speed
  23. velocity.z = input_vector.z * -speed
  24.  
  25.  
  26. else:
  27. velocity.x = 0
  28. velocity.z = 0
  29.  
  30. func _gravity(delta):
  31. if not is_on_floor():
  32. velocity.y -= gravity * delta
  33.  
  34.  
  35. func _jumpforce():
  36. if Input.is_action_just_pressed("jump") and is_on_floor():
  37. velocity.y = jump
  38.  
  39.  
  40.  
  41.  
  42.  
  43. velocity = move_and_slide(velocity, Vector3.UP)
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement