[SOLVED] How to compare two pc.Vec3 for equality?

Hello,
i’m trying to make a npc move but i am not sure about this function
if (this.newEnemyPos === pc.Vec3(0,0,0))
is this right?

That wont work. JavaScript does not allows to deeply compare object with == notation. This is something you have to implement.
Easiest here will be to use length method on Vec3, for that you can do this:

if (vecTarget.set(0, 0, 0).sub(this.newEnemyPos).length() === 0) {
    // enemy is exactly at vecTarget point

    // vecTarget needs to be prepared in advance
    // to prevent creating Vec3 each frame.
}

thanks a lot :smile:

LOL. Nice try @max

@ayrin, you need the equals function:

if (this.newEnemyPos.equals(pc.Vec3.ZERO)) {
    // your code here
}

mmmh this sound better but seems i have more troubles i guess i messed up my code

Also consider floating point precision. If you have two different vectors and want to see if they are at the same place, you’ll need a threshold:

vecTarget.set(0, 0, 0).sub(this.newEnemyPos).length() < 0.1