Open
Description
Hi, getting an error trying to use godot.lerp for Vector3 types (positions).
E 0:00:01.095 call_method: JavaScript Error at lerp (native)
at _process (res://src/Camera.jsx:22)
Call builtin function error lerp: Argument of type 'Vector3' is not assignable to parameter #0 of type 'float'
<C++ Source> modules/ECMAScript/quickjs/quickjs_binder.cpp:2125 @ call_method()
The documentation in godot.d.ts says that the function should accept Vector2, Vector3, or Color arguments, but it seems like it's only expecting floats at runtime.
/** Linearly interpolates between two values by a normalized value. This is the opposite of `inverse_lerp`.
If the `from` and `to` arguments are of type `int` or `float`, the return value is a `float`.
If both are of the same vector type (`Vector2`, `Vector3` or `Color`), the return value will be of the same type (`lerp` then calls the vector type's `linear_interpolate` method).
gdscript
lerp(0, 4, 0.75) # Returns 3.0
lerp(Vector2(1, 5), Vector2(3, 2), 0.5) # Returns Vector2(2, 3.5)
*/
function lerp(p_from: any, to: any, weight: number) : any;
I was able to easily get around this by writing a vector3 lerp function in typescript, but it would be nice to be able to use the builtin function:
function Vector3Lerp(
a: godot.Vector3,
b: godot.Vector3,
t: number
): godot.Vector3 {
return new godot.Vector3(
a.x * (1 - t) + b.x * t,
a.y * (1 - t) + b.y * t,
a.z * (1 - t) + b.z * t
);
}
Metadata
Metadata
Assignees
Type
Projects
Status
Backlog