godotjs / godotjs/javascript

godot.lerp errors for Vector3 not using the correct type

Abierto
#71 2 comentarios 0 reacciones 0 asignados Ver en GitHub
bug unit test
Lenguaje dominante
C++
Estrellas
1.1k
Forks
80
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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'
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.
```javascript
/** 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:
```typescript
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
);
}
```

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.