move_and_collide acting weird

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By GameSchool


I’m using move_and_collide to push an object, and it has weird reactions.

(Tell me if the video isn’t working)

If you don’t want to press the link, I show in that video that the player can push a box, but when it does the box is kind of vibrating (Don’t have better word for that), and if the player keep pushing it when it has no place to move, it just fall through the floor.

In the code, the cat is a CharacterBody2D and the box is RigidBody2D.


for index in get_slide_collision_count():
	var collision = get_slide_collision(index)
	if(collision.get_collider() is RigidBody2D and self.position.y + 6 > collision.get_collider().position.y):
		if(last_velocity.x > 0):
			collision.get_collider().move_and_collide(Vector2(0.5, 0))
			collision.get_collider().move_and_collide(Vector2(-0.5, 0))

last_velocity is updating when the current velocity isn’t (0,0) to detect if the player is moving right or left. If you have better ways to detect that I’ll ne happy to hear.

Thanks for the help