+1 vote

get slide collision has a range from -1 to 0, which one should I put and why?

in Engine by (183 points)

1 Answer

0 votes

From the docs:

Returns a KinematicCollision, which contains information about a collision that occurred during the last moveandslide call. Since the body can collide several times in a single call to moveandslide, you must specify the index of the collision in the range 0 to (getslidecount - 1).

It doesn't have a range of -1 to 0. Basically, in a single frame, move_and_slide can result in multiple collisions, and on each collision the slide function is called to get the new direction.

If you must iterate through collisions, do this:

for collision_index in range(get_slide_count()):
    var collision = get_slide_collision(collision_index)
by (1,086 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 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 webmaster@godotengine.org with your username.