local_game_jam_jan_2025/player/player.gd
Ethan Wellenreiter 99d09e2555 Initial commit
Has basic side to side movement and a basic jump

Signed-off-by: Ethan Wellenreiter <ewellenreiter@gmail.com>
2025-01-01 16:57:43 -05:00

37 lines
877 B
GDScript

extends CharacterBody2D
class_name Player
@export var SPEED = 300.0
@export var JUMP_VELOCITY = -400.0
func add_gravity(delta: float) -> void:
velocity += get_gravity() * delta
func _physics_process(delta: float) -> void:
var vertically_held : bool = false
if is_on_floor():
vertically_held = true
# handle the stuff here with if it's hanging at the time
# Add the gravity.
if not vertically_held:
add_gravity(delta)
# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var direction := Input.get_axis("ui_left", "ui_right")
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()