Look_at mouse position 90 degree offset issue

Godot Version

Godot Engine v4.2.2.stable.official.15073afe3

Question

I added rayCast2d on the map and want it to point at my mouse position using this code

ray_cast_2d.look_at(get_global_mouse_position())

but it points with 90 degrees offset to the left (like perpendicularly). I tried to change rotation in inspector or even put it under another 2d node and change rotation there. Nothing works.

any suggestions how to fix that? Ty.

I guess you are only rotating the RayCast2D node. The destination point is set as the target_position property.

1 Like

@FencerDevLog Thank you. I’ve learned something new. :blush:But I do want to rotate it. To make it point in the direction of my mouse position, not stretch it to the point. And the issue is that rayCast points perpendicularly to my mouse position. Like this:

O Ray Cast
l
l
l ------------------------------ o Mouse Position
l
l
l
V

Did you set your raycast’s target position to be a strictly right-facting, positive x axis value?

@gertkeno I’m a newbie. So I don’t know how to do it :sweat_smile:

few minutes later: Omg! It’s worked! So all i had to do is set x to 100(for example) and y to 0 in inspector. Literally make it face right. Thank you a lot! :+1:

1 Like

2024-08-07-125515_592x343_scrot

The raycast defaults to a downward facing target, set “Target Position” to say x 50, y 0

look_at assumes facing right is the correct way for 2D

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.