Advertisement
chris33556

09_07_2022

Jul 9th, 2022
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. extends KinematicBody
  2.  
  3. export var max_speed = 100
  4. export var gravity = 900
  5. export var jump_impulse = 250
  6. export var jump = false
  7.  
  8. var velocity = Vector3.ZERO
  9.  
  10. onready var animatedSprite = $AnimatedSprite3D
  11.  
  12. func _physics_process(delta):
  13. var input_vector = get_input_vector()
  14. apply_movement(input_vector)
  15. apply_gravity(delta)
  16. jump()
  17. if input_vector.x > 0:
  18. animatedSprite.animation = "walk"
  19. animatedSprite.flip_h = false
  20.  
  21. elif input_vector.x < 0:
  22. animatedSprite.animation = "walk"
  23. animatedSprite.flip_h = true
  24.  
  25. elif input_vector.z > 0:
  26. animatedSprite.animation = "walk"
  27.  
  28. elif input_vector.z < 0:
  29. animatedSprite.animation = "walk"
  30.  
  31. elif input_vector.y < 0:
  32. jump = true
  33. animatedSprite.animation = "jumping"
  34.  
  35. else:
  36. animatedSprite.animation = "idle"
  37.  
  38.  
  39.  
  40.  
  41.  
  42. velocity = move_and_slide(velocity, Vector3.UP)
  43.  
  44.  
  45. func get_input_vector():
  46. var input_vector = Vector3.ZERO
  47. input_vector.x = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
  48. input_vector.z = Input.get_action_strength("move_back") - Input.get_action_strength("move_forward")
  49.  
  50. return input_vector.normalized()
  51.  
  52.  
  53. func apply_movement(input_vector):
  54. velocity.x = input_vector.x * max_speed
  55. velocity.z = input_vector.z * max_speed
  56.  
  57.  
  58. func apply_gravity(delta):
  59. velocity.y -= gravity * delta
  60.  
  61.  
  62. func jump():
  63. if is_on_floor() and Input.is_action_pressed("jump"):
  64. jump == true
  65. velocity.y = jump_impulse
  66.  
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement