You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MotionCollision's get_angle() function can return NAN. According to the docs it should always return a positive value.
I believe I'm running into the same scenario as #8111 as applying a CLAMP within the acos() seems to fix the issue.
Steps to reproduce
In my case I had a platform that could rotate along the z axis and an independent character controller who's gravity would automatically adjust to the down vector of the rotating platform and the character controller would rotate towards the gravity so it's down vector also aligned with the platform's.
Using get_angle against the ground from the player's up direction would occasionally result in NAN at various platform rotations despite the vectors being perpendicular and normalized.
It would also seemingly result in weird behavior in move_and_slide() where the velocity would continuously have gravity added to it despite the character controller not moving.
In the minimal reproduction project there's a single scene with a platform that's named something along the lines of rotate me. If you run that project and slowly rotate the z axis from the remote tree eventually you should see an instance where "nan!" gets printed indicating it ran into the issue. It's very finicky and the character controller can fall through the platform so it might take a few tries.
Ah, this has come up before, imo we should be using a safe_acos() function in the majority of cases in the engine (with input clamped). It's very easy for float error to get outside the -1 to 1 range and cause Nan, and clamping is pretty cheap outside bottleneck code.
EDIT:
Yeah this bug is everywhere. In Godot case I think it might be better to make the default function safe, and add an extra unsafe_acos function for the rare occasions where it isn't needed. Same applies for asin, not sure if there is a similar conditions for other math funcs (maybe safe_sqrt), but I've most commonly seen it occur for acos.
Godot version
master (e684d12)
System information
Windows 10
Issue description
MotionCollision's get_angle() function can return NAN. According to the docs it should always return a positive value.
I believe I'm running into the same scenario as #8111 as applying a CLAMP within the acos() seems to fix the issue.
Steps to reproduce
In my case I had a platform that could rotate along the z axis and an independent character controller who's gravity would automatically adjust to the down vector of the rotating platform and the character controller would rotate towards the gravity so it's down vector also aligned with the platform's.
Using get_angle against the ground from the player's up direction would occasionally result in NAN at various platform rotations despite the vectors being perpendicular and normalized.
It would also seemingly result in weird behavior in move_and_slide() where the velocity would continuously have gravity added to it despite the character controller not moving.
In the minimal reproduction project there's a single scene with a platform that's named something along the lines of rotate me. If you run that project and slowly rotate the z axis from the remote tree eventually you should see an instance where "nan!" gets printed indicating it ran into the issue. It's very finicky and the character controller can fall through the platform so it might take a few tries.
Minimal reproduction project
GetAngle.zip
The text was updated successfully, but these errors were encountered: