Tweaked floaty area

This commit is contained in:
2026-02-08 20:59:30 +11:00
parent ab0f5efa30
commit 29ff9b1349
2 changed files with 35 additions and 25 deletions

View File

@@ -15,7 +15,8 @@ var just_bounced: bool = false #allow max bounce height (i.e. ignore jump input)
#floaty field
const FLOATY_RISING: int = -10
const FLOATY_FALLING: int = -30
var floaty_counter: int = 0
const FLOATY_HEIGHT_CLEAR: float = 1_000_000_000
var floaty_height: float = FLOATY_HEIGHT_CLEAR
#limits
const MAX_MOVE_SPEED: int = 300
@@ -24,49 +25,58 @@ const MAX_FLOATY_SPEED: int = -300
#boilerplate
func _ready():
clear_floaty_height()
_sprite.play("idle", 1)
#movement
func _physics_process(_delta) -> void:
#print(position.y, " ", floaty_height)
#jump input
if is_on_floor() and Input.is_action_just_pressed("input_jump"):
velocity.y -= JUMP_FORCE
if floaty_counter > 0:
#inverted - could tweak the rise?
#vertical movement
elif is_floaty() and position.y >= floaty_height: #below the floaty surface
if is_rising():
velocity.y += FLOATY_RISING
else:
velocity.y += FLOATY_FALLING
#fall faster than you rise
elif is_floaty() and position.y < floaty_height: ##above the floaty surface, but still floaty
if is_rising():
velocity.y += GRAVITY_FALLING #rise slower?
else:
var diff = floaty_height - position.y
position.y += log(diff)
velocity.y = 0
#normally, fall faster than you rise
elif is_rising() and (Input.is_action_pressed("input_jump") or just_bounced):
velocity.y += GRAVITY_RISING
else:
velocity.y += GRAVITY_FALLING
just_bounced = false
#terminal velocity
if floaty_counter > 0:
if velocity.y < MAX_FLOATY_SPEED:
velocity.y = MAX_FLOATY_SPEED
elif is_falling() and velocity.y > MAX_FALL_SPEED:
velocity.y = MAX_FALL_SPEED
print(velocity.y)
#input, walking
#sideways movement
var move_dir = Input.get_axis("input_left", "input_right")
#move with a maximum value
if move_dir:
_sprite.flip_h = move_dir < 0 #fancy
_sprite.flip_h = move_dir < 0 #fancy HD 4K graphics
velocity.x += MOVE_FORCE * move_dir
if abs(velocity.x) > MAX_MOVE_SPEED:
velocity.x = MAX_MOVE_SPEED * sign(velocity.x)
#no input, slow down
elif velocity.x != 0:
velocity.x = log(abs(velocity.x)) * sign(velocity.x)
#terminal velocity (in all directions)
if position.y > floaty_height and velocity.y < MAX_FLOATY_SPEED:
velocity.y = MAX_FLOATY_SPEED
if is_falling() and velocity.y > MAX_FALL_SPEED:
velocity.y = MAX_FALL_SPEED
if abs(velocity.x) > MAX_MOVE_SPEED:
velocity.x = MAX_MOVE_SPEED * sign(velocity.x)
#do the thing
move_and_slide()
@@ -87,10 +97,10 @@ func apply_bounce() -> void:
velocity.y = BOUNCE_FORCE
just_bounced = true
func enable_float() -> void:
floaty_counter += 1
pass
func set_floaty_height(height: float) -> void:
floaty_height = height
func disable_float() -> void:
floaty_counter -= 1
pass
func clear_floaty_height() -> void:
floaty_height = FLOATY_HEIGHT_CLEAR
func is_floaty() -> bool: return floaty_height != FLOATY_HEIGHT_CLEAR

View File

@@ -3,8 +3,8 @@ extends Area2D
func _on_body_entered(body) -> void:
#print("collision")
if body is BoxBoy:
body.enable_float()
body.set_floaty_height(position.y + $CollisionShape2D.shape.get_rect().position.y)
func _on_body_exited(body) -> void:
if body is BoxBoy:
body.disable_float()
body.clear_floaty_height()