# Moving a node in z direction, with World Coords

i am sure this is very basic transforming stuff, but i am afraid i am still struggling with Vectors, Quaternion, Rotation and all that.

So, i have this spaceship which fires weapons and those weapons have different lengths.

Both the spaceship and weapon are physic Nodes.

When a weapon is fired, i want to place the created projectile infront of the spaceship, so that they do not touch.

In my projectile Constructor i have the following variables:

```public MissileProjectile(final PhysicsSpace physics,                              final Vector3f direction,       // direction the Spaceship is looking (rotationColumn(2))                              final Vector3f startLocation,  // location of the weapon mounted on the Ship in WorldCoordiantes                              final Quaternion rotation) {   // current rotation of the spaceship     TriMesh model = new Cylinder("dummy missile model", 5, 5, 0.05f, 1.5f); // dummy model     updateModel(model); // (updates boundingboxes and physicsNode) }```

Right now, half of the missile is inside the spaceship BoundingBox of course.
How can i add the zExtent from the missile to the startLocation in the direction the Spaceship is currently facing?

spaceship.getlocalrotation() will give the direction of the node of the spaceship.

if u do have a model loaded to it, get the model spatial first then call getlocalrotation().

the method returns a quaternion(x,y,z,w) which defines the facing direction. then u take the x, y, z to form a vector3f and multiply this vector by the length of ur space ship. the result vector is the position of the head of ur spaceship. then u can figure out the rest depends on where ur wanna place the missle.

but becareful all the vectors u get r in local coordinate system.

mhh that dosen't seem to work.

If i multiply the rotation and add it to the startLocation, the Missile gets created behind and left or right of the Ship (depends on rotation).

When i create the Missile, i do already know the exact startingLocation, the Front of my SpaceShip's BoundingBox. This startlocation is in World coordinates.

What i also know, is the Rotation of the SpaceShip, and with that, the direction its heading.

Missile needs to start a bit in front of the Ship

/

====

if you have an initial heading (say looking up the z axis x0 y0 z1) then multiply this by the quaternion returned from getLocalRotation…

this will give you the new heading as a unit vector…

e.g.

Hinital = 0 0 1

Rotation = 90 degrees about Y

newH = Rotation * Hinitial = 1 0 0

• if your ship has a bounding radius of 10 and the projectile has a bounding radius of 5 then add the two together to get a magnitude for the displacement

rOffset = rship * rprojectile = 5 + 10 = 15

• now scale the modified heading vector

displacement = newH * rOffset = 15 0 0

• and if the ship is located at 20 0 50 then the missle location is

shipLoc + displacement = (15 0 0) + (20 0 50) = 35 0 50

i hope that helps…

sry i think i misunderstood ur question…

attach ur missle node to the ship node.

then translate the ship's front position from world coords into local coords.

``` Vector3f frontLocal= new Vector3f(); shipNode.worldToLocal(shipFrontWorldCoords, frontLocal) ```

calculate the missle's start position in local coords.

``` float missleLength = ((BoundingBox)missle.getWorldBound()).zExtent; frontLocal.addLocal(new Vector3f(0, 0, missleLength)); ```

place the missle at the start position.

``` missleNode.setLocalTranslation(frontLocal); ```