Compare commits

...

2 Commits

Author SHA1 Message Date
889680830a remove checking for collision 2025-08-22 15:39:30 +10:00
2ec8e893d4 make player fully stop when hitting floor 2025-08-22 15:38:56 +10:00
2 changed files with 30 additions and 30 deletions

View File

@@ -13,6 +13,7 @@ size = Vector2(18, 26)
[node name="Player" type="CharacterBody2D" node_paths=PackedStringArray("_trajectory")]
collision_layer = 16
floor_max_angle = 0.767945
floor_snap_length = 0.0
script = ExtResource("1_g2els")
_trajectory = NodePath("Trajectory")

View File

@@ -63,20 +63,20 @@ static func process_movement(
static func process_collision(
prev_velocity: Vector2,
new_velocity: Vector2,
slide_velocity: Vector2,
on_floor: bool,
on_ceiling: bool,
on_wall: bool,
wall_bounce_velocity_loss: float,
) -> Vector2:
if on_floor:
slide_velocity.x = 0
new_velocity = Vector2.ZERO
if on_ceiling:
slide_velocity.x *= wall_bounce_velocity_loss
new_velocity.x *= wall_bounce_velocity_loss
if on_wall:
slide_velocity.x = -new_velocity.x * wall_bounce_velocity_loss
return slide_velocity
new_velocity.x = -prev_velocity.x * wall_bounce_velocity_loss
return new_velocity
func _ready() -> void:
@@ -129,33 +129,32 @@ func _physics_process(delta: float) -> void:
# apply velocity
velocity = new_velocity
var collision_occured := move_and_slide()
move_and_slide()
# collisions
if collision_occured:
var on_floor := not is_on_floor_prev and is_on_floor()
var on_ceiling := not is_on_ceiling_prev and is_on_ceiling()
var on_wall := (
not is_on_wall_prev
and is_on_wall()
and not is_on_floor()
and not is_zero_approx(new_velocity.x)
)
velocity = process_collision(
new_velocity,
velocity,
on_floor,
on_ceiling,
on_wall,
_wall_bounce_velocity_loss,
)
if on_floor:
_trajectory.visible = false
collided.emit(SIDE_BOTTOM, new_velocity)
if on_ceiling:
collided.emit(SIDE_TOP, new_velocity)
if on_wall:
collided.emit(SIDE_LEFT if velocity.x > 0 else SIDE_RIGHT, new_velocity)
var on_floor := not is_on_floor_prev and is_on_floor()
var on_ceiling := not is_on_ceiling_prev and is_on_ceiling()
var on_wall := (
not is_on_wall_prev
and is_on_wall()
and not is_on_floor()
and not is_zero_approx(new_velocity.x)
)
velocity = process_collision(
new_velocity,
velocity,
on_floor,
on_ceiling,
on_wall,
_wall_bounce_velocity_loss,
)
if on_floor:
_trajectory.visible = false
collided.emit(SIDE_BOTTOM, new_velocity)
if on_ceiling:
collided.emit(SIDE_TOP, new_velocity)
if on_wall:
collided.emit(SIDE_LEFT if velocity.x > 0 else SIDE_RIGHT, new_velocity)
queue_redraw()