Jump to content

[Rotation, Quaternion] mesh tangent to a sphere


Théo Sabattié
 Share

Recommended Posts

Hi everyone ! :D

 

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

Sans titre - 1-01.png

sphere.png

Link to comment
Share on other sites

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

http://www.babylonjs-playground.com/#1XZ4XZ#20

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 

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...