Movable platform pushing character through walls
I am creating a block platform, which moves from the floor to the ceiling. The simplest way to implement this was with AnimatableBody2D. The platform can easily hold a player and move it up. The problem arises when the player would hit the ceiling or the floor while being on the platform. I would expect the platform to stop, but it pushes the player through the obstacles somehow and the physics get messed up.
I tried replacing the AnimatableBody2D with CharacterBody2D and simulating the movement with velocity. This seems easier for me, since this is also how I built the pushable block, so movable block can use similar code. Now the situation is somehow different. Now the block correctly stops when its trying to push the player into the ceiling or to the floor, but I am having hard time for it to work as a platform. When the player stands on it, it stops.
I tried preventing it by synchronizing the player movement with the platform, but it somehow does not work well. This is the process code for the platform:
func _process(delta: float) -> void:
`velocity = speed * _current_direction`
`var collision = move_and_collide(velocity * delta)`
`if _current_direction.y` `== -1:`
`if collision and collision.get_collider() is PlayerCharacter:`
`var remainder = collision.get_remainder()`
`var pushed_character = collision.get_collider()`
`var previous_velocity = pushed_character.velocity`
`pushed_character.move_and_collide(remainder * delta)`
`move_and_collide(remainder * delta)`
Posted Dec 13, 2025, 10:29 AM UTC