move_and_collide() and move_and_slide()

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

About collisions, how to know from which group are 2d objects when using move_and_collide instead of move_and_slide when is colliding with multiple objects?
it only detects one object

var collision = move_and_collide(velocity * delta)
if collision:

Thanks :slight_smile:

:bust_in_silhouette: Reply From: AlexTheRegent

move_and_slide use move_and_collide internally. It just calls move_and_collide again once collision is occurred until there is no movement left or max_slides calls of move_and_collide used. If you want to replace move_and_slide with move_and_collide, then you need to use same approach. After each collision you can get remain velocity (it is returned by move_and_collide function) and call move_and_collide again adjusting velocity along collision’s normal. Do it until remaining velocity is not zero (or at least close to zero) or max calls per frame is reached (you need to limit it too, because it might collide multiple hundreds times at some cases, freezing game).