Advertisement
chris33556

10_07_2022_jump_fix

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