Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | TheLoveDoctor |
I’ve been trying to use KinematicBody2D’s test_move() to see if my character is next to a wall, but not touching it, but I’m having a little trouble with it since the actual documentation is just
bool test_move( Transform2D from, Vector2 rel_vec, bool infinite_inertia=true )
Checks for collisions without moving the body. Virtually sets the node's position, scale and rotation to that of the given Transform2D, then tries to move the body along the vector rel_vec. Returns true if a collision would occur.
and all of the tutorials I could find just show an older version of the function where the only argument was a Vector2 which is a little more straightforward.
As far as I understand, the Transform2D is the objects initial position to test from, the Vector2 give the direction it should move, and infinite inertia deals with whether or not the object rotates on impact.
My issue right now is with the Transform2D, so far the only function I could find in the documentation that seems like it should return the objects transform in that format is CollisionObject2D’s
shape_owner_get_transform( int owner_id ) const
Returns the shape owner's Transform2D.
but no matter what I try I always seem to get an identity matrix out of it, the bit of code I ended up with trying to figure this out looks like
var transform2d = Transform2D(owner.shape_owner_get_transform(owner.get_shape_owners()[0]))
if owner.test_move(transform2d, Vector2(-20, 0), true):
print("on your left").
I’m not sure which function I’m misunderstanding, whether it’s test_move()
, shape_owner_get_transform()
, or get_shape_owners()
which I used to get the owner_id but any help would be appreciated.