mazelpomme Posted October 16, 2016 Share Posted October 16, 2016 Hi this topic is related to this one but it's not necessary to read it. So Théo Sabattié and I are trying to make a game in which the player controlls an airplane flying around a planet and is followed by an homing missile. To make the missile chase the player, we use plane :The plane is attached to the missile and the plane normal is the right vector of the missile. If the player is on the right side of the plane the missile rotate to the right (but stays tangent to the sphere) and if the player is on the left side it rotate to the left. This works at the begening but eventually it fails. And we don't get why. Does anyone know why ? Thanks Here is the playground version : http://www.babylonjs-playground.com/#1XZ4XZ#25 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted October 16, 2016 Share Posted October 16, 2016 Hi @mazelpomme and @Théo Sabattié @RaananW once made... what I call... an orthogonalizer. Maybe it should be called a perpendicularizer. Not sure if would be of any use to you, but here it is... http://www.babylonjs-playground.com/#2C8LVE#10 Of course, you would replace the monkey with an invisible cylinder/box... with a missile parented to the top of it. @jerome once helped someone make one, too, but I can't find that one. It was various cylinders placed around a sphere, each perpendicular to the sphere surface. Anyway, here is another thread with Jerome causing trouble... using ground-following. Not sure if this helps with your challenge or not. If you need terrain-following missiles, it should work well. The missiles should travel over the mountains and into the valleys of the planet, staying beneath radar. One more Jerome perpendicularizer? Okay. http://babylonjs-playground.com/#R7ZMI#10 You guys will still have the issue of "homing"... but these playgrounds and their funcs... might help keep your missiles parallel to the planet surface at all times. But maybe you have that handled, already. Quote Link to comment Share on other sites More sharing options...
mazelpomme Posted October 17, 2016 Author Share Posted October 17, 2016 (edited) Thanks for the quick reply @Wingnut. You guessed right the missile being parallel to the planet surface at all times part is already handled: The missile is parented to a pivot (empty mesh) which is positionned at the center of the sphere. To make the missile move we make the pivot rotate around the the missile right vector (which we get using calcMovePOV(1,0,0)) So the missile always move towards his nose cone. The real problem here is to get the missile following the player. The method we used is the following : we calculate the dot product between the right vector of the missile and the vector between the player and the missile. If the dot product is positive the missile rotation.y is decremented if not it's incremented. Here is the code sample (line 78 in the playground that I linked): missilePivot.rotate(missileTransform.calcMovePOV(1, 0, 0), 0.01); dotProduct = BABYLON.Vector3.Dot(missileTransform.calcMovePOV(1, 0, 0), missileTransform.getAbsolutePosition().subtract(playerTransform.getAbsolutePosition())); if (dotProduct > 0) { missileTransform.rotation.y -= 0.05; } else { missileTransform.rotation.y += 0.05; } But this only works at the begining and we don't get why... Is the math method wrong ? Did we missunderstood the method calcMovePov ? Edited October 17, 2016 by mazelpomme wrong statement Quote Link to comment Share on other sites More sharing options...
mazelpomme Posted October 20, 2016 Author Share Posted October 20, 2016 Problem solved ! Seems like missileTransform.calcMovePOV(1, 0, 0) didn't give us the right right vector, so the dot product was wrong. GameMonetize and Wingnut 2 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.