what is the index of collision?

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

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

:bust_in_silhouette: Reply From: Bernard Cloutier

From the docs:

Returns a KinematicCollision, which contains information about a collision that occurred during the last move_and_slide call. Since the body can collide several times in a single call to move_and_slide, you must specify the index of the collision in the range 0 to (get_slide_count - 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)