Why do move_and_collide and test_move seem to give conflicting results?

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

I’m trying to understand why move_and_collide can return a collision that isn’t null while test_move returns false in the following code:

var collision = node.move_and_collide(Vector2(), true, true, true)
var test = node.test_move(node.transform, Vector2())
print("collision: ",collision,"; test: ",test)

This will print collision: [KinematicCollision2D:2797]; test: False, even though, as far as I can tell, both methods are not actually moving, and instead just checking if the node is already colliding with another object.

:bust_in_silhouette: Reply From: rossunger

Did you check the results of the kinematicCollision2D that move_and_collide returns? it might say that there’s no collision! :slight_smile:

test_move returns true or false, and move_and_collide returns a kinematicCollision2D object which stores the collision data (which might be that there’s no collision)

I’m not sure what you mean. If there’s no collision, move_and_collide returns a null collision, so the above code would output collision: [Object:null]; test: False. If you try to get the collider from the null KinematicCollision2D, you get an error.

SweetPie | 2022-02-03 00:38