Rotating an object based upon direction of travel

I am developing a game where you launch a missile projectile. When I fire the missile into the air it flies a trajectory, however, the nose of the missile still points skywards when the missile starts heading towards the ground.

Is there a way of making the physics of the missile “nose heavy” so that the gravity makes the nose go down, or is there a function I can implement. Its not fun when a missile lands bottom first into a target. [import]uid: 63413 topic_id: 11211 reply_id: 311211[/import]

check out the ghosts vs. monsters code sample on the Ansca website. I modified their code (kind of hacked it together) to do something similar:

 local angleBetween = math.ceil(math.atan2( (valueY -   
 canonBall.y), (valueX - canonBall.x) ) \* 180 / math.pi) + 90   
 -- Formula: 90 + (math.atan2(y2 - y1, x2 - x1) \* 180 / PI)  
  
 -- restrict movement  
 local rotAmt = angleBetween + 180  
 if ((rotAmt-360) \>=0 and (rotAmt-360) \< 90) then  
 canonBall.rotation = angleBetween + 180   
 end  

Here I’m calculating the angle between the finger (valueX, valueY) and the canonBall’s x and y. Then I add 180 as I’m doing a pull back motion to fire so I’m switching the angle so that if I pull back and move u and down it rotates correctly. I do this at fire time so it shoots correctly.

I also restrict the angle of the shot.

Another idea is to use the physics editor (in the 3rd party tools) to create a shape that is nose heavy and make sure when y you “fire” it you don’t just shoot it straight up (make sure it has angle) and set the density to a good amount (4? 5?) and I would “think” the physics engine would take over as long as it has enough time to do so while in flight. I haven’t tested this myself yet.

Another thing to do is to calculate the arc from start to collision, and then determine the rotation and change it at intervals with a timer.

These are just some thoughts, hopefully someone will have a simple solution for you if those don’t help.

-d [import]uid: 27681 topic_id: 11211 reply_id: 40662[/import]

I agree that using the physics engine is the best way.

But that’s the question, how do I create a shape that is nose heavy, that still looks like a missile?

I’m using PhysicsEditor for objects. [import]uid: 63413 topic_id: 11211 reply_id: 40751[/import]

Ok I’ve worked it out. I created a physics shape of an inverted triangle, and then I set object.angularDamping to stop the missile from spinning uncontrollably
[import]uid: 63413 topic_id: 11211 reply_id: 40756[/import]

ya, that sounds good. Just remember that you don’t have to build a physics object that represents the actual art. You can create anything you want, and it’ll work fine. You just have to becareful that you don’t create some crazy collision issues like the tails is hit and nothing happens. I’d build a rectangle attached to that inverted triangle so the tail can still bounce right. Just make it very small.

You can also check it’s rotation to keep it from rotation to far. this is in the ghosts vs monsters example code.

-d [import]uid: 27681 topic_id: 11211 reply_id: 40840[/import]