Open Shou opened 2 months ago
gdnative is currently in maintenance mode (if at all), meaning we're quite hesitant to apply any changes that can be potentially breaking. This behavior has existed for a long time, and it's possible that some code relies on it. It's also documented as such (even if not explicitly, but that expression is NaN as well):
May I ask in which context you encountered this?
Note that in gdext (Godot 4 bindings), we indeed have multiple overloads with very explicit docs:
May I ask in which context you encountered this?
I have methods for pulling/pushing bodies towards/away from a specified position, and when that position is equal direction_to()
ends up making the vector NaN
. I wouldn't mind making a PR, but if it's unlikely to be accepted I'm fine either way. I mostly wanted to document this behavior as I tried searching for it here first.
We could maybe add a normalized_or_zero
method just like in gdext, but I'd rather not change the semantics of the existing one right now 🙂
Documenting would be a good idea, too.
@Shou are you interested in a PR that adds normalized_or_zero
?
In Godot,
Vector2.ZERO.normalized()
returnsVector2.ZERO
but the Rust equivalent usesglam
which seems to be the cause for returningNaN
(but I haven't verified). If that's the case, we should probably usenormalize_or
and return zero as the fallback instead.This affects any function that uses
normalized()
as well, likedirection_to()
.