Advertisement
Guest User

GDQuest Platformer Tutorial Jumping Issue

a guest
Nov 17th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. #=-=-=-=-=-=-=-= actor.gd =-=-=-=-=-=-=-=
  2.  
  3. extends KinematicBody2D
  4.  
  5. class_name Actor
  6.  
  7. const FLOOR_NORMAL = Vector2.UP
  8. export var speed: = Vector2(300.0,1000.0)
  9. export var gravity: = 500.0
  10. var velocity: = Vector2.ZERO
  11.  
  12. #=-=-=-=-=-=-=-= player.gd =-=-=-=-=-=-=-=
  13.  
  14. extends Actor
  15. var direction: = Vector2.ZERO
  16.  
  17. func _physics_process(delta: float) -> void:
  18. var direction: = get_direction() #returns a Vector 2
  19. velocity = calc_move_velo(velocity, direction, speed)
  20. velocity = move_and_slide(velocity, FLOOR_NORMAL)
  21.  
  22. func get_direction() -> Vector2:
  23. return Vector2(
  24. Input.get_action_strength("ui_right") -
  25. Input.get_action_strength("ui_left"),
  26. -1.0 if Input.is_action_just_pressed("ui_accept")
  27. and is_on_floor() else 0.0
  28. )
  29.  
  30. func calc_move_velo(
  31. linear_velocity: Vector2,
  32. speed: Vector2,
  33. direction: Vector2
  34. ) -> Vector2:
  35. var new_velocity: = linear_velocity
  36. new_velocity.x = speed.x * direction.x
  37. new_velocity.y += gravity * get_physics_process_delta_time()
  38. if direction.y == 1.0:
  39. new_velocity.y = speed.y * direction.y
  40. return new_velocity
  41.  
  42. #My current results is that my player falls, hits the ground, and moves around as expected.
  43. #It's just the jumping that isn't working. #I've also checked if the player is indeed on the ground,
  44. #if the jump input is being accepted, and I've tried to correct all new_velocity variables.
  45.  
  46. #Code by NerdyBirdyYTP on YouTube - https://www.youtube.com/channel/UCqa9oTtfHI52CSMJ1lZRTSA
  47. #I'll take any comments anywhere for followups and whatnot.
  48. #I'm also DeerTears on Github https://github.com/deertears/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement