Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends CharacterBody2D
- @export var SPEED: float
- @export var JUMP_FORCE: float
- @export var GRAVITY: float
- # Called when the node enters the scene tree for the first time.
- func _ready() -> void:
- pass # Replace with function body.
- # Called every frame. 'delta' is the elapsed time since the previous frame.
- func _process(delta: float) -> void:
- velocity = get_movement_vec()
- move_and_slide()
- print(get_movement_vec())
- func get_movement_vec():
- var val: Vector2
- var valy: float
- var valx
- if Input.is_action_pressed("right"):
- valx = -SPEED
- elif Input.is_action_pressed("left"):
- valx = SPEED
- valy = velocity.y + GRAVITY
- if is_on_floor():
- valy = Input.get_action_strength("up") * JUMP_FORCE
- val = Vector2(valx, valy)
- return val
Advertisement
Add Comment
Please, Sign In to add comment