0 votes

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

var collision = moveandcollide(velocity * delta)
if collision:
print(collision.collider.name)

Thanks :)

in Engine by (12 points)

1 Answer

+3 votes

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).

by (1,650 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.