I have some important elements in my game which could be used to gain massive velocity and essentialy break the game. So I want to set the max number for velocity.y. Also the game is in 3D so can't use clamp.

Godot version v3.3.2
in Engine
edited

I don't understand why 3d stops you from using clamp

``````velocity.y=clamp(velocity.y, 0, max_speed)
``````

Or better

``````velocity.y=min(max_speed, velocity.y)
``````

Clamp can only be used in 2D.

clamp is a core script function, it takes a float value and return the value if inside the range, or min/max if outside the range.
3D, 2D, control nodes, resources, makes no difference

https://docs.godotengine.org/en/stable/classes/[email protected]#class-gdscript-method-clamp

it's like saying that `sin(x)` only works in 2D

you are probably confusing with the method Vector2(x,y).clamped(10), which returns a vector2 whose length is clamped.
in that case, you can easily workaround with the below formula (which is true both in 2D and 3D)

``````vec.clamped(value)=vec.normalized*min(vec.length(), value)
``````

``````if velocity.y > 500: