d0p3t / fivem-js

Javascript and Typescript wrapper for the FiveM natives API
https://d0p3t.nl
Other
143 stars 57 forks source link

[BUG] Vector manipulation doesn't work #49

Closed coblyox closed 3 years ago

coblyox commented 3 years ago

Vector3 manipulation doesn't work, for example normalize method / accessor gives null all the time. Because of that, other methods which uses normalize, returns null also.

To Reproduce Steps to reproduce the behavior: Simple code example:

import { Vector3 } from 'fivem-js'

const [x, y, z] =  GetPedBoneCoords(PlayerPedId(), 31086, 0.0, 0.0, 0.0)
const vector = new Vector3(x, y, z)
console.log(vector.normalize)

Expected behavior Should return normalized vector, instead returns:

{ "x": null, "y": null, "z": null }

FiveM Client (please complete the following information):

FiveM Server (please complete the following information):

d0p3t commented 3 years ago

normalize is a method. Have you tried vector.normalize()? Not true, I see it is a getter. Weird.

coblyox commented 3 years ago
import { Vector3 } from 'fivem-js'

const [x, y, z] =  GetPedBoneCoords(PlayerPedId(), 31086, 0.0, 0.0, 0.0)
console.log(Vector3.normalize(new Vector3(x, y, z)))

Gives same result.

coblyox commented 3 years ago

Hi! Maybe there's some update on this?

d0p3t commented 3 years ago

I've been extremely busy IRL. I will look at it latest next weekend.

coblyox commented 3 years ago

No worries, I thought I would just ask.

lfshr commented 3 years ago

Ended up debugging this as GameplayCamera.ForwardVector wasn't working.

https://github.com/d0p3t/fivem-js/blob/12a1684f39553050345aeab382be54abafad3d11/src/utils/Vector3.ts#L56-L58 https://github.com/d0p3t/fivem-js/blob/12a1684f39553050345aeab382be54abafad3d11/src/utils/Vector3.ts#L121-L123 https://github.com/d0p3t/fivem-js/blob/12a1684f39553050345aeab382be54abafad3d11/src/utils/Vector3.ts#L72-L75

Vector subtracts itself and then multiplies 0 by 0 (due to subtraction). Essentially this.dotProduct(this.subtract(this)) which returns 0 as the length, causing the normalize method to divide by 0.

lfshr commented 3 years ago

@niunisas this should be fixed in version 1.5.2

d0p3t commented 3 years ago

As said by lfshr: This has been fixed in 1.5.2

If there are any remaining issues, please open a new Issue.