Théo Sabattié Posted October 7, 2016 Share Posted October 7, 2016 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 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted October 7, 2016 Share Posted October 7, 2016 hello hello! can you reproduce this in the playground so we can help you fixing it? Quote Link to comment Share on other sites More sharing options...
JohnK Posted October 7, 2016 Share Posted October 7, 2016 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. Quote Link to comment Share on other sites More sharing options...
mazelpomme Posted October 13, 2016 Share Posted October 13, 2016 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.