- Removed jumping code
- Add clinging to ceiling upon touch
This commit is contained in:
parent
ca14c26a2d
commit
4df996690e
1 changed files with 25 additions and 31 deletions
|
|
@ -1,23 +1,25 @@
|
||||||
extends CharacterBody2D
|
extends CharacterBody2D
|
||||||
|
|
||||||
const MOVE_SPEED = 200.0
|
const MOVE_SPEED = 150.0
|
||||||
const CLIMB_SPEED = -150.0
|
const CLIMB_SPEED = -150.0
|
||||||
const JUMP_VELOCITY = -250.0
|
const JUMP_VELOCITY = -250.0
|
||||||
|
|
||||||
# Time window (in seconds) on when to auto-jump when pressing jump key
|
|
||||||
# before landing on the ground.
|
|
||||||
const TOTAL_JUMP_BUFFER_S = 0.1
|
|
||||||
var jumpBufferTimeLeft = 0.0
|
|
||||||
|
|
||||||
const WALL_SLIDE_MODIFIER = 0.1
|
const WALL_SLIDE_MODIFIER = 0.1
|
||||||
const ROTATE_TO_WALL_SPEED = 25 # How quickly to rotate the sprite when clinging to a wall.
|
const ROTATE_TO_WALL_SPEED = 25 # How quickly to rotate the sprite when clinging to a wall.
|
||||||
|
const CEILING_STICK_SPEED = -20.0 # Small upward push that keeps the slime pressed against the ceiling.
|
||||||
|
|
||||||
# Temp for now, need to use aniamtedspite2d later on
|
# Temp for now, need to use aniamtedspite2d later on
|
||||||
@onready var sprite = $Sprite2D
|
@onready var sprite = $Sprite2D
|
||||||
|
|
||||||
|
# is_on_ceiling() is only true on frames where we actually bumped the ceiling,
|
||||||
|
# so we remember that we're stuck to it here.
|
||||||
|
var isClingingToCeiling := false
|
||||||
|
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
# Update sprite to be on the wall
|
# Update sprite to be on the ceiling or wall
|
||||||
if not is_on_floor() and is_on_wall():
|
if isClingingToCeiling:
|
||||||
|
sprite.rotation = lerp_angle(sprite.rotation, PI, ROTATE_TO_WALL_SPEED * delta)
|
||||||
|
elif not is_on_floor() and is_on_wall():
|
||||||
sprite.rotation = lerp_angle(sprite.rotation, PI/2 * get_wall_normal().x, ROTATE_TO_WALL_SPEED * delta)
|
sprite.rotation = lerp_angle(sprite.rotation, PI/2 * get_wall_normal().x, ROTATE_TO_WALL_SPEED * delta)
|
||||||
else:
|
else:
|
||||||
sprite.rotation = lerp_angle(sprite.rotation, 0.0, ROTATE_TO_WALL_SPEED * delta)
|
sprite.rotation = lerp_angle(sprite.rotation, 0.0, ROTATE_TO_WALL_SPEED * delta)
|
||||||
|
|
@ -30,35 +32,27 @@ func _physics_process(delta: float) -> void:
|
||||||
# Quick flip sprite thing.
|
# Quick flip sprite thing.
|
||||||
if horizontalInput: sprite.flip_h = (horizontalInput < 0)
|
if horizontalInput: sprite.flip_h = (horizontalInput < 0)
|
||||||
|
|
||||||
# If you're pressing against the wall, stick to it.
|
# Pressing down lets go of the ceiling. Zeroing velocity.y means we start
|
||||||
# If you're just touching the wall, slowly ooze down it.
|
# falling right away, instead of drifting up and sticking again.
|
||||||
# If you're not touching anything, fall normally.
|
if isClingingToCeiling and verticalInput < 0:
|
||||||
if is_on_wall() and horizontalInput != 0:
|
isClingingToCeiling = false
|
||||||
velocity.y = 0.0
|
velocity.y = 0.0
|
||||||
|
|
||||||
|
# If on the ceiling, stay pressed against it.
|
||||||
|
# If touching the wall, stick to it or move up/down.
|
||||||
|
# Else, fall normally if not on floor.
|
||||||
|
if isClingingToCeiling:
|
||||||
|
velocity.y = CEILING_STICK_SPEED
|
||||||
elif is_on_wall():
|
elif is_on_wall():
|
||||||
velocity.y += get_gravity().y * WALL_SLIDE_MODIFIER * delta
|
velocity.y = CLIMB_SPEED * verticalInput
|
||||||
elif not is_on_floor():
|
elif not is_on_floor():
|
||||||
velocity.y += get_gravity().y * delta
|
velocity.y += get_gravity().y * delta
|
||||||
|
|
||||||
# Jumping! And also jump buffering.
|
|
||||||
"""
|
|
||||||
if Input.is_action_just_pressed("jump") and not (is_on_floor() or is_on_wall()):
|
|
||||||
jumpBufferTimeLeft = TOTAL_JUMP_BUFFER_S
|
|
||||||
print("start jump buffer")
|
|
||||||
|
|
||||||
if ((Input.is_action_just_pressed("jump") or jumpBufferTimeLeft > 0.0)
|
|
||||||
and is_on_floor()):
|
|
||||||
velocity.y = JUMP_VELOCITY
|
|
||||||
jumpBufferTimeLeft = 0.0
|
|
||||||
if jumpBufferTimeLeft > 0.0:
|
|
||||||
jumpBufferTimeLeft -= delta
|
|
||||||
"""
|
|
||||||
|
|
||||||
# Quick setup for oozing up walls
|
|
||||||
if verticalInput > 0 and is_on_wall():
|
|
||||||
velocity.y = CLIMB_SPEED
|
|
||||||
|
|
||||||
if horizontalInput: velocity.x = horizontalInput * MOVE_SPEED
|
if horizontalInput: velocity.x = horizontalInput * MOVE_SPEED
|
||||||
else: velocity.x = move_toward(velocity.x, 0, MOVE_SPEED)
|
else: velocity.x = move_toward(velocity.x, 0, MOVE_SPEED)
|
||||||
|
|
||||||
move_and_slide()
|
move_and_slide()
|
||||||
|
|
||||||
|
# Touching the ceiling sticks us to it. Crawling off the ceiling's edge
|
||||||
|
# means we're not touching it anymore, so we start falling.
|
||||||
|
isClingingToCeiling = is_on_ceiling()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue