godotjs / godotjs/javascript

godot.lerp errors for Vector3 not using the correct type

オープン
#71 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る
bug unit test
主要言語
C++
スター
1.1k
フォーク
80
PR マージ指標
30日以内にマージされた PR はありません

説明

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
);
}
```

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。