Proper arrow rotation

I appear to be stuck at a certain part of my game. I have an arrow that fires through the air, but it doesnt rotate towards the ground like a normal arrow would, it just stays horizontal. I understand this is happening because there isn’t any air resistance causing it to rotate properly.

So my question is how could I make it so that it rotates properly. My only thought would be to apply a small force upwards to the tail of the arrow. But i was wondering if anyone had any better solutions.

Any help is welcomed. Thanks.

-Nick Homme
[import]uid: 11769 topic_id: 12251 reply_id: 312251[/import]

Well, you could rotate it manually or you could, perhaps, consider making the head and body of the arrow two different physics bodies joined to one another, with the arrow head being heavier (slightly) than the body.

It’s just a theory, I haven’t played with multi-element bodies in a long while, but figured two suggestions were better than one :wink:

Peach :slight_smile: [import]uid: 52491 topic_id: 12251 reply_id: 44656[/import]

or you could just use simple math:
http://en.wikipedia.org/wiki/Trigonometry

-- get distance  
dX = targetX-arrow.x  
dY = targetY-arrow.y   
  
-- calculate rotation  
arrow.rotation = math.atan2(dY, dX)/(math.pi/180) + 90;  

didn’t test it, but something like this should work.

-finefin
[import]uid: 70635 topic_id: 12251 reply_id: 44668[/import]

Thank you both! Even though I did not use your your guys’s answers exactly they did help me come up with a solution. That solution being that I set a “magnetic” body 30 pixels to the right and quite a ways down of my arrow and I have said magnet use a “magnetic force” to pull the arrow head toward the magnet thus causing the head to head down properly. (That’s a rough sumerization of how it works.)

If you want I can explain how I came to my current solution.

Also I will be uploading a little sample of this to the Code Exchange.

-Nick Homme

[EDIT] link to the sample code: http://developer.anscamobile.com/code/arrow-basics [import]uid: 11769 topic_id: 12251 reply_id: 44692[/import]