Untitled
unknown
python
2 years ago
744 B
3
Indexable
Never
extends KinematicBody2D var x: int = 0 var speed: int = 300 var run_speed: int = 600 var jump_height: int = 12000 var is_running: bool = false var is_jumping: bool = false func _input(event): if event.is_action_pressed("move_r"): x = 1 elif event.is_action_pressed("move_l"): x = -1 else: x = 0 is_running = event.is_action_pressed("run") is_jumping = event.is_action_pressed("jump") func _physics_process(delta): var gravity: int var is_touching_floor = is_on_floor() if !is_touching_floor and is_jumping: gravity = 250 else: gravity = 600 var vec = Vector2(x * speed, gravity) if is_running: vec.x = x * run_speed elif is_touching_floor and is_jumping: vec.y = -jump_height vec = move_and_slide(vec, Vector2.UP)