# 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?

https://playcanvas.com/pryme8/space_flight_testing 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.

Thanks!

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

this.entity.translate(v3.x,v3.y,v3.z);
``````

Entities also provide their direction vectors

`this.entity.forward`

`this.entity.right`

`this.entity.up`

So you can do:

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

Or using method chaining:

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

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

1 Like