Deriving translation from pitch and yaw in 3D space

I have an airplane model and I just want it to fly in the direction that is pointing. Right now I am using getEulerAngles() and doing some cos and sin calculations on the x y z in order to get some kind of forward vector.

It isn’t working though. Is there anything built in for this? you can take a look at that for some references…

we have gone over some of that stuff… If I had it 100% figured out id break it down for you but Its been a work in progress to get yaw pitch and roll correct.


Since I posted I found some formulas that I incorporated. This code seems to be doing the trick:

        var quat = this.entity.getRotation(); 
        var x = quat.x;
        var y = quat.y;
        var z = quat.z; 
        var w = quat.w;

        var 3 = new pc.Vec3( 2 * (x * z + w * y),  2 * (y * z - w * x), 1 - 2 * (x * x + y * y));


Entities also provide their direction vectors




So you can do:

var dir = new pc.Vec3();

Or using method chaining:

var dir = new pc.Vec3().copy(this.entity.forward).scale(2);

This is what I was looking for. This works and I like getting away from extra calculations and magic numbers. Thank you.

1 Like