move_and_slide not detecting collision with AnimatableBody2D when walking against wall

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

My player character, a CharacterBody2D, is standing on an AnimatableBody2D that serves as a vertically moving platform. Right next to this platform is a wall. In my code, each frame, I check if the player is standing on this platform to call another method.

Normally,get_slide_collision() returns a collision with the AnimatableBody2D. But when the player walks against the wall, get_slide_collision() only returns the collision with the wall. This is causing me problems, since the method that relies on the collision with the platform is not being called.

Interestingly, is_on_floor still returns true in those cases, even though move_and_slidedoes not detect a collision with what is currently the floor (the platform).

Here is the relevant code in the CharacterBody2D script:

move_and_slide();

for index in get_slide_collision_count():
	var collision = get_slide_collision(index)
	var collider = collision.get_collider();
		
	if collider is AnimatableBody2D:
		# call a function