|
|
|
|
@ -5,17 +5,6 @@ const AIR_SPEED = 75.0
|
|
|
|
|
|
|
|
|
|
const CLIMB_SPEED = -150.0
|
|
|
|
|
|
|
|
|
|
# Acceleration on floors, walls and ceilings. Full speed in 4 frames, stopped in 6.
|
|
|
|
|
const GROUND_ACCEL = GROUND_SPEED / (4.0 / 60.0)
|
|
|
|
|
const GROUND_FRICTION = GROUND_SPEED / (6.0 / 60.0)
|
|
|
|
|
# In the air we steer more gently, and keep any extra speed we had when we left
|
|
|
|
|
# a surface instead of snapping down to AIR_SPEED.
|
|
|
|
|
const AIR_ACCEL = 600.0
|
|
|
|
|
const AIR_DRAG = 300.0
|
|
|
|
|
const MAX_FALL_SPEED = 400.0
|
|
|
|
|
# How far we'll pull back onto a wall/ceiling we're sticking to if we drift off it.
|
|
|
|
|
const SURFACE_SNAP_DISTANCE = 4.0
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
const WALL_STICK_SPEED = 20.0 # Small push into the wall that keeps the slime pressed against it.
|
|
|
|
|
@ -26,13 +15,6 @@ const WALL_STICK_SPEED = 20.0 # Small push into the wall that keeps the slime pr
|
|
|
|
|
@onready var edgeSensors: Node2D = $EdgeSensors
|
|
|
|
|
@onready var leftEdgeSensor: RayCast2D = $EdgeSensors/LeftEdgeSensor
|
|
|
|
|
@onready var rightEdgeSensor: RayCast2D = $EdgeSensors/RightEdgeSensor
|
|
|
|
|
@onready var splatParticles: CPUParticles2D = $SplatParticles
|
|
|
|
|
@onready var landSound: AudioStreamPlayer = $LandSound
|
|
|
|
|
@onready var wrapSound: AudioStreamPlayer = $WrapSound
|
|
|
|
|
# Placeholder sounds, see Assets/Sounds/CREDITS.txt. One is picked at random
|
|
|
|
|
# for each landing, at a slightly random pitch, so they don't all sound the same.
|
|
|
|
|
@export var landSounds: Array[AudioStream] = []
|
|
|
|
|
const MIN_LAND_SPEED = 60.0 # Slower impacts than this don't splat.
|
|
|
|
|
|
|
|
|
|
# How long to press opposite direction before unsticking from a wall/ceiling
|
|
|
|
|
const MAX_SECS_TO_UNSTICK = 0.5
|
|
|
|
|
@ -50,8 +32,6 @@ var lipDirection := 0.0 # Which way we were moving when we went over the lip.
|
|
|
|
|
# After climbing onto a wall from a lip we're usually still holding away from it,
|
|
|
|
|
# so don't count that towards unsticking until the direction is released.
|
|
|
|
|
var ignoreWallUnstickUntilRelease := false
|
|
|
|
|
# Same for down after wrapping onto a ceiling (e.g. crawling down a wall and under).
|
|
|
|
|
var ignoreCeilingUnstickUntilRelease := false
|
|
|
|
|
|
|
|
|
|
# Edge wrapping: instead of relying on physics to slide around a corner, the
|
|
|
|
|
# slime swings around it on a quarter circle so it always feels the same.
|
|
|
|
|
@ -65,8 +45,8 @@ var wrapFromDistance := 0.0
|
|
|
|
|
var wrapToDistance := 0.0
|
|
|
|
|
var wrapFromRotation := 0.0
|
|
|
|
|
var wrapToRotation := 0.0
|
|
|
|
|
var wrapSpeed := 0.0 # Eases up to GROUND_SPEED, so starting from a standstill isn't a jolt.
|
|
|
|
|
var wrapTravelled := 0.0
|
|
|
|
|
var wrapDuration := 0.0
|
|
|
|
|
var wrapProgress := 0.0
|
|
|
|
|
var wrapArcLength := 0.0
|
|
|
|
|
var wrapExitOffset := Vector2.ZERO # Straight move after the arc, onto the new surface.
|
|
|
|
|
var wrapOntoNormal := Vector2.UP # Normal of the surface we end up on.
|
|
|
|
|
@ -78,34 +58,28 @@ var wrapEntryLength := 0.0
|
|
|
|
|
# we're on, a little way to each side of us. If one stops touching the surface,
|
|
|
|
|
# there's an edge within edgeSensorRange on that side, and pressing into the
|
|
|
|
|
# surface will slide over it onto the side of the platform.
|
|
|
|
|
@export var edgeSensorRange := 12.0
|
|
|
|
|
@export var edgeSensorRange := 24.0
|
|
|
|
|
var wallFacingY := -1.0 # Which way we last moved along a wall (-1 is up).
|
|
|
|
|
|
|
|
|
|
# Holding at an edge: moving along a surface towards its edge stops at the edge,
|
|
|
|
|
# and only lets go after holding towards it for MAX_SECS_TO_UNSTICK.
|
|
|
|
|
var timeSpentHoldingEdge := 0.0
|
|
|
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
|
floor_snap_length = SURFACE_SNAP_DISTANCE
|
|
|
|
|
var sensorDepth := _get_radius() + 4
|
|
|
|
|
leftEdgeSensor.position = Vector2(-edgeSensorRange, 0)
|
|
|
|
|
leftEdgeSensor.target_position = Vector2(0, sensorDepth)
|
|
|
|
|
rightEdgeSensor.position = Vector2(edgeSensorRange, 0)
|
|
|
|
|
rightEdgeSensor.target_position = Vector2(0, sensorDepth)
|
|
|
|
|
# The sensors' parent is the EdgeSensors pivot, so exclude_parent doesn't
|
|
|
|
|
# cover us. Without this they can hit our own collider.
|
|
|
|
|
leftEdgeSensor.add_exception(self)
|
|
|
|
|
rightEdgeSensor.add_exception(self)
|
|
|
|
|
|
|
|
|
|
# Rotates the sprite to sit on the wall or ceiling. Done in _physics_process
|
|
|
|
|
# (not _process) so physics interpolation smooths it along with our movement.
|
|
|
|
|
func _update_sprite_rotation(delta: float) -> void:
|
|
|
|
|
# In a corner only one of these is ever true (decided in _physics_process).
|
|
|
|
|
var target := 0.0
|
|
|
|
|
if not is_on_floor() and isStickingToWall: target = PI/2 * wallNormalX
|
|
|
|
|
elif isStickingToCeiling: target = PI
|
|
|
|
|
# Exponential smoothing, so it turns at the same rate at any frame rate.
|
|
|
|
|
sprite.rotation = lerp_angle(sprite.rotation, target, 1.0 - exp(-ROTATE_TO_WALL_SPEED * delta))
|
|
|
|
|
func _process(delta: float) -> void:
|
|
|
|
|
# The wrap sets the sprite rotation itself.
|
|
|
|
|
if isWrapping: return
|
|
|
|
|
|
|
|
|
|
# Update sprite to be on the wall or ceiling. In a corner only one of them
|
|
|
|
|
# is ever true (that gets decided at the end of _physics_process).
|
|
|
|
|
if not is_on_floor() and isStickingToWall:
|
|
|
|
|
sprite.rotation = lerp_angle(sprite.rotation, PI/2 * wallNormalX, ROTATE_TO_WALL_SPEED * delta)
|
|
|
|
|
elif isStickingToCeiling:
|
|
|
|
|
sprite.rotation = lerp_angle(sprite.rotation, PI, ROTATE_TO_WALL_SPEED * delta)
|
|
|
|
|
else:
|
|
|
|
|
sprite.rotation = lerp_angle(sprite.rotation, 0.0, ROTATE_TO_WALL_SPEED * delta)
|
|
|
|
|
|
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
|
|
|
# Get the input direction and handle the movement/deceleration.
|
|
|
|
|
@ -120,8 +94,6 @@ func _physics_process(delta: float) -> void:
|
|
|
|
|
_update_wrap(delta)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
var wasInAir := _get_surface_normal() == Vector2.ZERO and not isClimbingLip
|
|
|
|
|
|
|
|
|
|
# Hanging on a lip and pressing up: swing around onto the wall above.
|
|
|
|
|
var wantsToClimb := verticalInput > 0 or timeSinceUpPressed <= CLIMB_INPUT_BUFFER
|
|
|
|
|
if isClimbingLip and wantsToClimb and _start_lip_wrap():
|
|
|
|
|
@ -141,8 +113,7 @@ func _physics_process(delta: float) -> void:
|
|
|
|
|
# Vertical Input Controls
|
|
|
|
|
if isStickingToCeiling:
|
|
|
|
|
# If on ceiling, pressing down long enough unsticks from ceiling.
|
|
|
|
|
if verticalInput >= 0: ignoreCeilingUnstickUntilRelease = false
|
|
|
|
|
if verticalInput < 0 and not ignoreCeilingUnstickUntilRelease: timeSpentUnstickingCeiling += delta
|
|
|
|
|
if verticalInput < 0: timeSpentUnstickingCeiling += delta
|
|
|
|
|
else: timeSpentUnstickingCeiling = 0.0
|
|
|
|
|
if timeSpentUnstickingCeiling >= MAX_SECS_TO_UNSTICK:
|
|
|
|
|
isStickingToCeiling = false
|
|
|
|
|
@ -150,13 +121,13 @@ func _physics_process(delta: float) -> void:
|
|
|
|
|
else: velocity.y = CEILING_STICK_SPEED
|
|
|
|
|
# Move up and down along a wall when sticking to it.
|
|
|
|
|
elif isStickingToWall:
|
|
|
|
|
velocity.y = _accelerate(velocity.y, CLIMB_SPEED * verticalInput)
|
|
|
|
|
velocity.y = CLIMB_SPEED * verticalInput
|
|
|
|
|
# Don't fall if climbing lip. Pressing up climbs onto the wall above.
|
|
|
|
|
elif isClimbingLip:
|
|
|
|
|
velocity.y = CLIMB_SPEED if verticalInput > 0 else 0.0
|
|
|
|
|
# Else... just fall.
|
|
|
|
|
elif not is_on_floor():
|
|
|
|
|
velocity.y = minf(velocity.y + get_gravity().y * delta, MAX_FALL_SPEED)
|
|
|
|
|
velocity.y += get_gravity().y * delta
|
|
|
|
|
|
|
|
|
|
# Horizontal Input Controls
|
|
|
|
|
# If sticking to a wall, pressing away from it long enough gets us unstuck.
|
|
|
|
|
@ -176,23 +147,19 @@ func _physics_process(delta: float) -> void:
|
|
|
|
|
# slide around the corner and touch the wall.
|
|
|
|
|
if isClimbingLip:
|
|
|
|
|
velocity.x = -lipDirection * WALL_STICK_SPEED if verticalInput > 0 else 0.0
|
|
|
|
|
elif is_on_floor() or isStickingToCeiling:
|
|
|
|
|
velocity.x = _accelerate(velocity.x, horizontalInput * GROUND_SPEED)
|
|
|
|
|
elif horizontalInput and (is_on_floor() or isStickingToCeiling):
|
|
|
|
|
velocity.x = horizontalInput * GROUND_SPEED
|
|
|
|
|
elif horizontalInput and not (is_on_floor() or isStickingToCeiling):
|
|
|
|
|
velocity.x = horizontalInput * AIR_SPEED
|
|
|
|
|
else:
|
|
|
|
|
velocity.x = _air_steer(velocity.x, horizontalInput)
|
|
|
|
|
|
|
|
|
|
_hold_at_edge(delta)
|
|
|
|
|
velocity.x = move_toward(velocity.x, 0, GROUND_SPEED)
|
|
|
|
|
|
|
|
|
|
var wasOnWall := isStickingToWall and not is_on_floor()
|
|
|
|
|
var velocityBeforeMove := velocity
|
|
|
|
|
|
|
|
|
|
move_and_slide()
|
|
|
|
|
|
|
|
|
|
# Check if we should be sticking to walls/ceiling after moving our player.
|
|
|
|
|
# If we drifted slightly off the wall (and aren't trying to let go), pull
|
|
|
|
|
# back onto it instead of falling off.
|
|
|
|
|
isStickingToWall = is_on_wall() or (wasOnWall and timeSpentUnstickingWall < MAX_SECS_TO_UNSTICK \
|
|
|
|
|
and _snap_to_surface(Vector2(wallNormalX, 0)))
|
|
|
|
|
isStickingToWall = is_on_wall()
|
|
|
|
|
# Climbed past the top of a wall: swing over onto the floor on top.
|
|
|
|
|
if wasOnWall and not isStickingToWall and verticalInput > 0 \
|
|
|
|
|
and timeSpentUnstickingWall < MAX_SECS_TO_UNSTICK and _start_wall_top_wrap():
|
|
|
|
|
@ -208,12 +175,10 @@ func _physics_process(delta: float) -> void:
|
|
|
|
|
isClimbingLip = false
|
|
|
|
|
else: timeSpentUnstickingLip = 0.0
|
|
|
|
|
var wasJustOnCeiling = isStickingToCeiling
|
|
|
|
|
isStickingToCeiling = is_on_ceiling() or (wasJustOnCeiling and _snap_to_surface(Vector2.DOWN))
|
|
|
|
|
isStickingToCeiling = is_on_ceiling()
|
|
|
|
|
# Only walking off the ceiling's edge counts as a lip, not landing on
|
|
|
|
|
# a ceiling, letting go of it by pressing down, or after already holding
|
|
|
|
|
# at the edge long enough to let go.
|
|
|
|
|
if wasJustOnCeiling and not isStickingToCeiling and not isStickingToWall and velocity.x \
|
|
|
|
|
and timeSpentHoldingEdge < MAX_SECS_TO_UNSTICK:
|
|
|
|
|
# a ceiling or letting go of it by pressing down.
|
|
|
|
|
if wasJustOnCeiling and not isStickingToCeiling and not isStickingToWall and velocity.x:
|
|
|
|
|
isClimbingLip = true
|
|
|
|
|
lipDirection = signf(velocity.x)
|
|
|
|
|
# Made it onto the wall from the lip.
|
|
|
|
|
@ -229,51 +194,6 @@ func _physics_process(delta: float) -> void:
|
|
|
|
|
else:
|
|
|
|
|
isStickingToCeiling = false
|
|
|
|
|
|
|
|
|
|
# Just landed on something: squish.
|
|
|
|
|
var normal := _get_surface_normal()
|
|
|
|
|
if wasInAir and normal != Vector2.ZERO and velocityBeforeMove.dot(-normal) >= MIN_LAND_SPEED:
|
|
|
|
|
_splat(normal)
|
|
|
|
|
|
|
|
|
|
_update_sprite_rotation(delta)
|
|
|
|
|
|
|
|
|
|
# Moves speed towards target: GROUND_ACCEL when speeding up, GROUND_FRICTION
|
|
|
|
|
# when slowing down or stopping.
|
|
|
|
|
func _accelerate(speed: float, target: float) -> float:
|
|
|
|
|
var speedingUp := target != 0.0 and (speed == 0.0 or signf(target) == signf(speed)) and absf(target) > absf(speed)
|
|
|
|
|
return move_toward(speed, target, (GROUND_ACCEL if speedingUp else GROUND_FRICTION) * get_physics_process_delta_time())
|
|
|
|
|
|
|
|
|
|
# Horizontal steering in the air. Extra speed from leaving a surface fades
|
|
|
|
|
# slowly unless we steer against it.
|
|
|
|
|
func _air_steer(speed: float, horizontalInput: float) -> float:
|
|
|
|
|
var delta := get_physics_process_delta_time()
|
|
|
|
|
var target := horizontalInput * AIR_SPEED
|
|
|
|
|
var keepingMomentum := absf(speed) > AIR_SPEED and (horizontalInput == 0.0 or signf(horizontalInput) == signf(speed))
|
|
|
|
|
if keepingMomentum or horizontalInput == 0.0:
|
|
|
|
|
return move_toward(speed, target, AIR_DRAG * delta)
|
|
|
|
|
return move_toward(speed, target, AIR_ACCEL * delta)
|
|
|
|
|
|
|
|
|
|
# If the surface with this normal is within SURFACE_SNAP_DISTANCE, move flush
|
|
|
|
|
# against it and return true. Only counts if we'd hit it head on, so sliding
|
|
|
|
|
# off an edge and catching its corner doesn't pull us back around.
|
|
|
|
|
func _snap_to_surface(normal: Vector2) -> bool:
|
|
|
|
|
var motion := -normal * SURFACE_SNAP_DISTANCE
|
|
|
|
|
var hit := move_and_collide(motion, true)
|
|
|
|
|
if not hit or hit.get_normal().dot(normal) < 0.9: return false
|
|
|
|
|
global_position += hit.get_travel()
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
|
|
# Squish sound and a little burst of slime where we hit the surface.
|
|
|
|
|
func _splat(normal: Vector2) -> void:
|
|
|
|
|
splatParticles.global_position = global_position - normal * _get_radius()
|
|
|
|
|
# It's a jump to a new spot, not movement, so don't interpolate from the last one.
|
|
|
|
|
splatParticles.reset_physics_interpolation()
|
|
|
|
|
splatParticles.direction = normal
|
|
|
|
|
splatParticles.restart()
|
|
|
|
|
if landSounds:
|
|
|
|
|
landSound.stream = landSounds.pick_random()
|
|
|
|
|
landSound.pitch_scale = randf_range(0.87, 1.15)
|
|
|
|
|
landSound.play()
|
|
|
|
|
|
|
|
|
|
func _get_radius() -> float:
|
|
|
|
|
return (collisionShape.shape as CircleShape2D).radius
|
|
|
|
|
|
|
|
|
|
@ -366,55 +286,20 @@ func _try_edge_wrap(normal: Vector2, tangent: Vector2, side: float) -> bool:
|
|
|
|
|
# A sensor starting inside something is an inside corner, not an edge.
|
|
|
|
|
if not _is_point_free(sensor.global_position): return false
|
|
|
|
|
var dir := tangent * side
|
|
|
|
|
var corner = _find_edge_corner(normal, dir, edgeSensorRange + 2)
|
|
|
|
|
if corner == null: return false
|
|
|
|
|
# Slide to just past the corner, swing around it, then carry on along the
|
|
|
|
|
# side of the platform so we end up flat against it.
|
|
|
|
|
return _begin_wrap(corner, dir.angle(), -normal * _get_radius(), dir, normal.angle())
|
|
|
|
|
|
|
|
|
|
# Finds the corner where the surface we're on (facing normal) ends, up to reach
|
|
|
|
|
# ahead of us in dir. Returns null if there's no edge that close.
|
|
|
|
|
func _find_edge_corner(normal: Vector2, dir: Vector2, reach: float) -> Variant:
|
|
|
|
|
var radius := _get_radius()
|
|
|
|
|
var pos := global_position
|
|
|
|
|
# The surface we're on, checked from the side away from the edge.
|
|
|
|
|
var surfaceFrom := pos - dir * radius * 0.5
|
|
|
|
|
var surfaceHit := _cast_ray(surfaceFrom, surfaceFrom - normal * radius * 2)
|
|
|
|
|
if not surfaceHit or surfaceHit.normal.dot(normal) < 0.5: return null
|
|
|
|
|
# Side of the platform, just inside its surface, looking back from reach
|
|
|
|
|
# ahead. If the surface carries on past reach, the ray starts inside it
|
|
|
|
|
# and finds nothing.
|
|
|
|
|
if not surfaceHit or surfaceHit.normal.dot(normal) < 0.5: return false
|
|
|
|
|
# Side of the platform, just inside its surface, looking back from past the sensor.
|
|
|
|
|
var line: Vector2 = surfaceHit.position - normal * 2 + dir * (pos - surfaceHit.position).dot(dir)
|
|
|
|
|
var faceHit := _cast_ray(line + dir * reach, line - dir * radius)
|
|
|
|
|
if not faceHit or faceHit.normal.dot(dir) < 0.5: return null
|
|
|
|
|
var faceHit := _cast_ray(line + dir * (edgeSensorRange + 2), line - dir * radius)
|
|
|
|
|
if not faceHit or faceHit.normal.dot(dir) < 0.5: return false
|
|
|
|
|
var corner: Vector2 = faceHit.position + normal * 2
|
|
|
|
|
# A real edge has empty space just past it, behind the surface. Seams
|
|
|
|
|
# between tiles (and the foot of a wall) have solid there, so they're not edges.
|
|
|
|
|
if not _is_point_free(corner + dir * 2 - normal * 2): return null
|
|
|
|
|
return corner
|
|
|
|
|
|
|
|
|
|
# If this frame's movement along the surface would take us past its edge, stop
|
|
|
|
|
# at the edge instead, until we've held towards it for MAX_SECS_TO_UNSTICK.
|
|
|
|
|
func _hold_at_edge(delta: float) -> void:
|
|
|
|
|
var normal := _get_surface_normal()
|
|
|
|
|
var tangent := normal.orthogonal()
|
|
|
|
|
var speed := velocity.dot(tangent)
|
|
|
|
|
if normal == Vector2.ZERO or is_zero_approx(speed):
|
|
|
|
|
timeSpentHoldingEdge = 0.0
|
|
|
|
|
return
|
|
|
|
|
var dir := tangent * signf(speed)
|
|
|
|
|
# Climbing up past the top of a wall swings over onto it instead.
|
|
|
|
|
if absf(normal.x) > 0.5 and dir.y < 0: return
|
|
|
|
|
var step := absf(speed) * delta
|
|
|
|
|
var corner = _find_edge_corner(normal, dir, step + 1)
|
|
|
|
|
var distanceToEdge: float = INF if corner == null else (corner - global_position).dot(dir)
|
|
|
|
|
if distanceToEdge > step:
|
|
|
|
|
timeSpentHoldingEdge = 0.0
|
|
|
|
|
return
|
|
|
|
|
# Held long enough: let go and carry on over the edge.
|
|
|
|
|
if timeSpentHoldingEdge >= MAX_SECS_TO_UNSTICK: return
|
|
|
|
|
timeSpentHoldingEdge += delta
|
|
|
|
|
velocity += dir * (maxf(distanceToEdge, 0.0) / delta - absf(speed))
|
|
|
|
|
# Slide to just past the corner, swing around it, then carry on along the
|
|
|
|
|
# side of the platform so we end up flat against it.
|
|
|
|
|
return _begin_wrap(corner, dir.angle(), -normal * radius, dir, normal.angle())
|
|
|
|
|
|
|
|
|
|
# Starts swinging around corner to toAngle from it, then moving by exitOffset,
|
|
|
|
|
# ending up stuck to the surface facing ontoNormal.
|
|
|
|
|
@ -443,22 +328,17 @@ func _begin_wrap(corner: Vector2, toAngle: float, exitOffset: Vector2, ontoNorma
|
|
|
|
|
wrapOntoNormal = ontoNormal
|
|
|
|
|
# Keep the same speed as crawling along a surface.
|
|
|
|
|
wrapArcLength = absf(angle_difference(wrapFromAngle, wrapToAngle)) * radius
|
|
|
|
|
wrapTravelled = 0.0
|
|
|
|
|
# Start at the speed we were already going, so crawling into a wrap is seamless.
|
|
|
|
|
wrapSpeed = minf(velocity.length(), GROUND_SPEED)
|
|
|
|
|
wrapDuration = maxf((wrapEntryLength + wrapArcLength + exitOffset.length()) / GROUND_SPEED, 0.05)
|
|
|
|
|
wrapProgress = 0.0
|
|
|
|
|
velocity = Vector2.ZERO
|
|
|
|
|
isWrapping = true
|
|
|
|
|
wrapSound.play()
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
|
|
func _update_wrap(delta: float) -> void:
|
|
|
|
|
# Speed up to crawling speed like we would on a surface.
|
|
|
|
|
wrapSpeed = move_toward(wrapSpeed, GROUND_SPEED, GROUND_ACCEL * delta)
|
|
|
|
|
var totalLength := wrapEntryLength + wrapArcLength + wrapExitOffset.length()
|
|
|
|
|
wrapTravelled = minf(wrapTravelled + wrapSpeed * delta, totalLength)
|
|
|
|
|
# The distance travelled is split between the straight entry, the arc and
|
|
|
|
|
# the straight exit by their lengths.
|
|
|
|
|
var travelled := wrapTravelled
|
|
|
|
|
wrapProgress = minf(wrapProgress + delta / wrapDuration, 1.0)
|
|
|
|
|
# Progress is split between the straight entry, the arc and the straight
|
|
|
|
|
# exit by their lengths.
|
|
|
|
|
var travelled := wrapProgress * (wrapEntryLength + wrapArcLength + wrapExitOffset.length())
|
|
|
|
|
var arcStart := wrapCorner + Vector2.from_angle(wrapFromAngle) * wrapFromDistance
|
|
|
|
|
if travelled < wrapEntryLength:
|
|
|
|
|
global_position = wrapEntryStart.lerp(arcStart, travelled / wrapEntryLength)
|
|
|
|
|
@ -471,18 +351,14 @@ func _update_wrap(delta: float) -> void:
|
|
|
|
|
var distance := lerpf(wrapFromDistance, wrapToDistance, arcProgress)
|
|
|
|
|
global_position = wrapCorner + Vector2.from_angle(angle) * distance + wrapExitOffset * exitProgress
|
|
|
|
|
sprite.rotation = lerp_angle(wrapFromRotation, wrapToRotation, arcProgress)
|
|
|
|
|
if wrapTravelled < totalLength: return
|
|
|
|
|
if wrapProgress < 1.0: return
|
|
|
|
|
|
|
|
|
|
# Close the small gap left by WRAP_MARGIN so we're touching the new surface.
|
|
|
|
|
# Done with move_and_slide so is_on_floor()/is_on_wall() are up to date
|
|
|
|
|
# instead of still describing where we were before the wrap.
|
|
|
|
|
velocity = -wrapOntoNormal * (WRAP_MARGIN + 1) / delta
|
|
|
|
|
move_and_slide()
|
|
|
|
|
# Carry on at the same speed along the new surface, so leaving the wrap
|
|
|
|
|
# isn't a sudden stop. Normal movement then speeds up or slows down from here.
|
|
|
|
|
var exitDirection := wrapExitOffset.normalized() if wrapExitOffset != Vector2.ZERO \
|
|
|
|
|
else Vector2.from_angle(wrapToAngle).orthogonal()
|
|
|
|
|
velocity = exitDirection * wrapSpeed
|
|
|
|
|
velocity = Vector2.ZERO
|
|
|
|
|
|
|
|
|
|
isWrapping = false
|
|
|
|
|
isClimbingLip = false
|
|
|
|
|
@ -491,4 +367,3 @@ func _update_wrap(delta: float) -> void:
|
|
|
|
|
if isStickingToWall:
|
|
|
|
|
wallNormalX = wrapOntoNormal.x
|
|
|
|
|
ignoreWallUnstickUntilRelease = true
|
|
|
|
|
ignoreCeilingUnstickUntilRelease = isStickingToCeiling
|
|
|
|
|
|