-
-
Notifications
You must be signed in to change notification settings - Fork 21k
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
Add "clamped" method to Vector3 #30058
Comments
Very simple to add, do you have a use case in mind? I had a look and the Vector2 version is only used twice I think in the source, both times in joints_2d_sw.cpp. It is also exposed in gdscript. |
Well, I usually clamp input direction vectors to 1 (as one should) and velocities to a max speed, among other things. I've been using if-statements to do this, but having a dedicated helper method for this would turn 2-3 lines of code into 1. Nothing essential, but it would be pretty convenient... |
For this you should use |
You'd want to clamp if you also wanted to read directional inputs from an analog stick (ignoring the fact that some controllers' sticks can go beyond a magnitude of 1 at intercardinal directions). |
When building geometries (meshes) procedurally, I extensively use normalize and then scale, which clamp is a shortcut for if I'm not mistaken. I don't especially need the perf boost, since those are run during dev only, but it'd be nice to get rid of my custom |
I've certainly used 'Normalize and scale' more often than the clamped method, and I'd argue for that before clamped which seems to be a special case. The existing clamped 2d function is this:
NormalizeToScale is more like this:
Although in practice I'd probably return something to indicate whether it was too small to normalize to catch errors. Can clamped use the same (p_len / l)? It's doing more operations .. unless it is for precision reasons. |
See also: #13926 (comment) The name of |
I agree with this addition. The use cases are the same as |
Godot version
3.2-dev 6fbd045
I noticed
Vector2
has a method namedclamped
, which returns the Vector2 with its length clamped to thelength
parameter. It would be nice to have the same forVector3
.The text was updated successfully, but these errors were encountered: