# Align head of arrow with body

## Recommended Posts

Hey, is there any way to get the arrow heads in this demo to align with the body of the arrow?

I can get the rotation right for some of the sectors such as +x,+y, and +z but the other sectors don't work. I'm fairly new to babylon and I don't know if there is a function to do this.

I realize it might be possible to do with multiple if statements but I would prefer not to do it that way.

http://www.babylonjs-playground.com/#XPA7I#1

Please let me know if there is any way to do this,

Thanks

##### Share on other sites

If you know the final orientation in terms of axis (or vectors) but you don't know what rotation to apply to your cylinder to align it with one of these final vectors, you could use the static RotationFromAxis() method.

Documented here ("Generating a rotation from a target system" part ) : http://doc.babylonjs.com/page.php?p=22411

##### Share on other sites

It also seems to work with lookAt:

`var vector = new BABYLON.Vector3(magx, magy, magz)var draw_vector = BABYLON.Mesh.CreateLines("lines", [new BABYLON.Vector3(0, 0, 0),vector], scene);var head1 = BABYLON.Mesh.CreateCylinder("head1", 3, 0, 2, 10, 1, scene);head1.position = vector;head1.lookAt(vector.scale(2), 0, -Math.PI/2, 0);`

http://www.babylonjs-playground.com/#XPA7I#2

##### Share on other sites

yep

lookAt() rotates the mesh by aligning its local z axis (if I remember well) to the target

RotationFromAxis(axis1, axis2, axis3) creates a angle triplet (pitch, yaw, roll) what can be used to rotate then a mesh and to align it with axis1, axis2 and axis3 along its own local x, y and z axis

##### Share on other sites

Thanks for the help!

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.