Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

look_at_from_position: Up vector and direction between node origin and target are aligned, look_at() failed. #53793

Open
Nukiloco opened this issue Oct 14, 2021 · 4 comments

Comments

@Nukiloco
Copy link

Nukiloco commented Oct 14, 2021

Godot version

v3.4.beta4.official [6a058cb]

System information

Windows 10, Nvidia GTX 750Ti

Issue description

I would like to know why the up vector and direction between node origin and target being aligned is considered an error and why I have to add checks to make sure its directly not Vector3.Up and Vector3.Down. This seriously does not make since to me at all. Shouldn't it just be the default rotation of being upwards or downwards? If there is some complex reason why this is like this, can it have some sort of documentation? Thanks!

Steps to reproduce

Note that this is is just a example of a line that would cause the error:

var collision_normal_up = Vector3.UP
var collision_normal_down = Vector3.DOWN

spatial.look_at(collision_normal_up, Vector3.UP) # Returns a error
spatial.look_at(collision_normal_down, Vector3.UP) # Returns a error

Minimal reproduction project

No response

@lawnjelly
Copy link
Member

lawnjelly commented Oct 14, 2021

This is down to maths - it is because if your up vector is up, and you want to look up, you still have an undefined rotation around the up axis. Not only that, as you approach the up axis, you will immediately swap from a defined rotation to an undefined rotation, and you will also get some randomisation going on of the rotation due to floating point error.

How you should best handle this depends on the case.

Godot could have gdscript return some standard rotation I guess, but it would usually lead to other visual errors because the user is not handling the situation properly.

What you are probably imagining is if you were told right now to look up, you would look up but your yaw would be the same as your previous yaw. But the look_at function is defined with no concept of this previous yaw. Instead you have to do this bit yourself.

@nathanfranke
Copy link
Contributor

If you tell me to look_at(the_ceiling) in real life, I will naturally use the same yaw as I currently have. This error makes sense probably for some Transform methods, but I think Spatial.look_at is high level enough that having a fallback is reasonable.

@Lippanon
Copy link

It would be nice if there was such a function that assumes the same yaw, or such like alternative. The majority of use cases for "look_at" and "look_at_from_position" use the default up vector (Vector3.UP). When calling "look_at" every physics tick, to avoid the error it's annoying to need a check in GDScript (like 'not up.cross(-target.normalized()).is_zero_approx()') that is already done by the function itself in c++ (see note 1. below), particularly for performance reasons, since I'm happy just keeping the same rotation that tick. Is this not a common use case?

Note 1.:

ERR_FAIL_COND_V_MSG(v_x.is_zero_approx(), Basis(), "The target vector and up vector can't be parallel to each other.");

ERR_FAIL_COND_MSG(p_up.cross(p_target - p_pos).is_zero_approx(), "Up vector and direction between node origin and target are aligned, look_at() failed.");

Related issue as mentioned by lawnjelly: #57457

@r3a1d3a1
Copy link

A more intuitive alternative: look_at_direction
It'd take a single arg: direction (not destination).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants