+1 vote

I'm trying to understand why moveandcollide 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.

Godot version 3.4
in Engine by (69 points)
edited by

1 Answer

0 votes

Did you check the results of the kinematicCollision2D that moveandcollide returns? it might say that there's no collision! :)

testmove returns true or false, and moveand_collide returns a kinematicCollision2D object which stores the collision data (which might be that there's no collision)

by (1,340 points)

I'm not sure what you mean. If there's no collision, moveandcollide 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.

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.