Negative Vec3 syntax

Quick question - when I do:

dir = this.entity.forward;

I can later do:

if (!dir.equals(pc.Vec3.ZERO)) { ... }

But when set dir as:

dir = -this.entity.forward;

I get an error saying equals is not a function. It looks like I can’t simply use the ‘-’ here, just want to confirm if that’s the case. Would I have to multiply by -1 instead?


I think you should try testing the multiplying by -1, you seem to be right on it!

Chhes :cheese:

Hi @MattN,

Javascript as a programming language doesn’t provide operation overloading. You will have to use the scale method that internally multiplies each vector element:

dir = this.entity.forward.scale(-1);
1 Like

Thanks folks, I used mulScalar as suggested which did the trick!

1 Like

Ah right, that method was renamed, need to change that scale() habit, thanks @MattN !