lakewood/Assets/Characters/Friendly/Tellik/tellick.gd
2024-09-07 14:12:04 -04:00

61 lines
1.4 KiB
GDScript

extends CharacterBody2D
const SPEED = 600.0
const JUMP_VELOCITY = -1000.0
const MAX_JUMP_DURATION = 0.3
const MIN_JUMP_DURATION = 0.01
const GRAVITY = 980
const FALL_GRAVITY_MULTIPLIER = 2
var jump_timer = 0.0
var is_jumping = false
@onready var actionableFinder: Area2D = $Marker2D/ActionableFinder
func _unhandled_input(event: InputEvent) -> void:
if Input.is_action_just_pressed("ui_accept"):
var actionables = actionableFinder.get_overlapping_areas()
if actionables.size() > 0:
actionables[0].action()
return
func _physics_process(delta):
# Apply gravity
if not is_on_floor():
var gravity_multiplier = FALL_GRAVITY_MULTIPLIER if velocity.y > 0 else 2
velocity.y += GRAVITY * gravity_multiplier * delta
# Handle Jump
if Input.is_action_just_pressed("jump") and is_on_floor():
start_jump()
if is_jumping:
if Input.is_action_pressed("jump"):
continue_jump(delta)
else:
end_jump()
# Handle horizontal movement
var direction = Input.get_axis("move_left", "move_right")
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()
func start_jump():
velocity.y = JUMP_VELOCITY
is_jumping = true
func continue_jump(delta):
pass
func end_jump():
if velocity.y < 0:
velocity.y *= 0.20
is_jumping = false
func _on_kill_zone_body_entered(body: Node2D) -> void:
pass # Replace with function body.