Advertisement
otorp2

kinebody gravity* delta

Dec 26th, 2016
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. extends KinematicBody2D
  2.  
  3. var velocity = Vector2(6,0)
  4. const gravity = Vector2(0,1)
  5. func _ready():
  6. set_fixed_process(true)
  7.  
  8. pass
  9.  
  10. func _fixed_process(delta):
  11. velocity += gravity * delta
  12.  
  13. move(velocity)
  14. think we are good
  15. thanks this room is a lifesaver
  16. Ross - Today at 4:53 PM
  17. Imagine you are only processing once every second. Gravity is an acceleration. Every second you move that much faster than the previous second. So velocity gets gravity added in every second. And velocity is in pixels per second, it's how far you move every second.
  18.  
  19. So if you were processing 4 times a second, delta would be 0.25 seconds. So you only want to add 0.25 gravity to velocity, etc.
  20.  
  21.  
  22.  
  23. extends KinematicBody2D
  24.  
  25. var velocity = Vector2(100,0)
  26. const gravity = Vector2(0,30)
  27. func _ready():
  28. set_fixed_process(true)
  29.  
  30. pass
  31.  
  32. func _fixed_process(delta):
  33. velocity += gravity *delta
  34.  
  35. move(velocity*delta)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement