Guest User

Untitled

a guest
Feb 29th, 2024
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. extends CharacterBody2D
  2.  
  3. @export var SPEED: float
  4. @export var JUMP_FORCE: float
  5. @export var GRAVITY: float
  6.  
  7.  
  8. # Called when the node enters the scene tree for the first time.
  9. func _ready() -> void:
  10. pass # Replace with function body.
  11.  
  12.  
  13. # Called every frame. 'delta' is the elapsed time since the previous frame.
  14. func _process(delta: float) -> void:
  15. velocity = get_movement_vec()
  16.  
  17. move_and_slide()
  18. print(get_movement_vec())
  19.  
  20.  
  21. func get_movement_vec():
  22. var val: Vector2
  23. var valy: float
  24. var valx
  25. if Input.is_action_pressed("right"):
  26. valx = -SPEED
  27. elif Input.is_action_pressed("left"):
  28. valx = SPEED
  29. valy = velocity.y + GRAVITY
  30. if is_on_floor():
  31. valy = Input.get_action_strength("up") * JUMP_FORCE
  32.  
  33. val = Vector2(valx, valy)
  34.  
  35. return val
Advertisement
Add Comment
Please, Sign In to add comment