# [Rotation, Quaternion] mesh tangent to a sphere

## Recommended Posts

Hi everyone !

I am making a game with a friend (mazelpomme):

The player controls an airplane.

It rotates around a sphere and missiles try to touch it, so missiles align themself with the player.

To align missiles on player, we worked with Cross product, Dot product with the down missile's vector and the vector "missile to sphere's center" (@see uploaded images)

currently, our code is:

``````missile.lookAt(Player.getInstance().getAbsolutePosition());

var missiletoCenter : BABYLON.Vector3 = missile.getAbsolutePosition().negate();
var missileDown : BABYLON.Vector3 = missile.down.getAbsolutePosition().subtract(missile.getAbsolutePosition());
var angle : number = Math.acos(BABYLON.Vector3.Dot(missiletoCenter.normalize(), missileDown.normalize()));
var axis : BABYLON.Vector3 = BABYLON.Vector3.Cross(missiletoCenter, missileDown);
missile.rotate(axis, angle);``````

sphere center position is x0, y0, z0

We didn't undestand why that didn't work because we reproduced the same in unity and that worked.

(missile.down is a missile's child placed on down missile's axis)

Has someone an idea?

Can you help us?

Thanks

Théo & mazelpomme

##### Share on other sites

hello hello!

can you reproduce this in the playground so we can help you fixing it?

##### Share on other sites

This topic

Works on a similar problem but normals rather than tangents to a sphere. It may help. See Jeromes last post January 7 for playground examples.

##### Share on other sites

Hey, sorry for the late answer, here is the reproduction in the playground

So, we would like the homing missile (the red one) to follow the player (the blue one) Both move around the sphere using rotation around the planet center. The homing missile aims for the player using mesh.lookAt, The problem there is that the missile isnt tangent to the sphere so we would like to adjust the rotation to make it tangent again. Yet this code doesn't work.

I hope i wasn't too messy in my explanation

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