martian-mike/scripts/player.gd
2024-11-01 20:33:00 +03:00

21 lines
508 B
GDScript

extends CharacterBody2D
@export var speed = 300.0
@export var jump_velocity = 400.0
func _physics_process(delta: float) -> void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
# Handle jump.
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = -jump_velocity
# Get the input direction and handle the movement/deceleration.
var direction := Input.get_axis("move_left", "move_right")
velocity.x = direction * speed
move_and_slide()