godotjs / godotjs/javascript

godot.lerp errors for Vector3 not using the correct type

Đang mở
#71 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
bug unit test
Ngôn ngữ chính
C++
Star
1.1k
Fork
80
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.