clamped() doesn't work (godot 4.0)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By terebi

Hello, I’m trying to learn godot4.0 using HeartBeast action RPG tutorial (which is on the older version of Godot) and everything was fine until I tried to use clamped()

am I missing something?

:bust_in_silhouette: Reply From: zhyrin

The godot editor has a built-in documentation.
You can Ctrl+Click on a type (Vector2 in this case) and see it’s entire description.
It says it doesn’t have a clamped() function, you can confirm it for yourself.
Instead it has a function called clamp(), but it doesn’t take the same kind of parameter.

Checking out the online documentation (specifically the 3.x) version, you can see in the description of Vector2.clamped() that it is depricated, and limit_length() should be used instead. This function is present in the 4.0 version as well.

As a side note, CharacterBody2D has a built-in velocity member, you don’t need to define it yourself.

zhyrin | 2023-03-24 09:36

thanks a lot ! yes I had to use limit_length() instead of clamped(), it works perfectly fine now.

terebi | 2023-03-24 09:49