RayCast2D rotating

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By trafel
:warning: Old Version Published before Godot 3 was released.

Hi, I was wondering if there was an easier way of disabling the raycast rotation without having to mess with its rotation matrix.

I have a ball that rolls in a flat ground with a raycast attached to it that tells me if the ball touches the ground.

EDIT :

After messing with the matrix, I figured out how to transform the object without rotating it based on the ball’s matrix. I changed the parent of the raycast to be the top node2d (World). But I think its now making problems with the display or something. the raycast has exactly the same coordinates as the ball, but it’s sprite just wont show. Maybe it’s changing the value of its z-index ?

Here is the code :

ray_origin = get_transform().get_origin()
ray_scale = get_transform().get_scale()
ray_rotation = Vector2(0, 0)
raycast_down.set_transform(Matrix32(ray_scale, ray_rotation, ray_origin))
print(raycast_down.get_transform())

EDIT2 :

The output tells me that the raycast doesnt collide no matter how rotated the ball is. So the transformation matrix returned is wrong ?

EDIT3 :

I think it really is a display bug since the camera I’ve attached to the raycast follows the ball. But the fact that the is_colliding() function doesn’t return true still confuses me.

:bust_in_silhouette: Reply From: trafel

It is actually possible to access the raycast rotation properties directly in its object. So in the fixed process loop, just execute this code :

raycast_down.set_rot(-get_rot())

I had seen this kind of problem coming when developing my game: if you have a rigidbody as parent and it rotates, all children will rotate. However, what if you only want the sprite to rotate, and not particle system, sample player, other sprites, raycasts etc?
With your solution we counter the rotation. It seems to work, but it feels a bit awkwards because it cancels automatic computations by adding more computations.
Maybe we could tell nodes to ignore parts of parent’s transform through flags? Or maybe there is another way?

Zylann | 2016-06-10 12:34

I agree. An override for individual parts of a parents transform would be nice.
Also I remembered something from when I was playing with the physics of circular objects. You have to use the raycast2D.update() function to have it update visually if your using the debugging options to show collisions.

independentCog | 2016-06-10 16:07