Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #PlayerScript
  2. extends Actor
  3.  
  4.  
  5. func _physics_process(delta: float) -> void:
  6. var direction = get_direction()
  7. velocity = calculate_move_velocity(velocity, direction, speed)
  8. velocity = move_and_slide(velocity, Vector2.UP)
  9.  
  10.  
  11. func get_direction() -> Vector2:
  12. return Vector2(
  13. Input.get_action_strength("movie_right") - Input.get_action_strength("move_left"),
  14. -1.0 if Input.is_action_just_pressed("jump") and is_on_floor() else 1.0
  15. )
  16.  
  17.  
  18. func calculate_move_velocity(
  19. linear_velocity: Vector2,
  20. direction: Vector2,
  21. speed: Vector2
  22. ) -> Vector2:
  23. var new_velocity: = linear_velocity
  24. new_velocity.x = speed.x * direction.x
  25. new_velocity.y += gravity * get_physics_process_delta_time()
  26. if direction.y == -1.0:
  27. new_velocity.y = speed.y * direction.y
  28. return new_velocity
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement