Hello there, I am trying to simulate an arrow toss in my game but I am having a big problem. The arrow is simulated as a whole object, but I wanted its head to be heavier, so that the arrow would fall with it pointing downward when falling.
I tried creating two mesh type parts, but it didn't really work (the collision detection is perfect tough) because the mass is set to the object, not to the parts.
Any ideas?
I tried to look if there is a way to define the gravity center, but found only a get function.
My other idea was to use two separated objects (one for the head and one for the tail). Is there any way I can create two separated objects and join then by using a joint? Couldn't find any method on the API doc that was obviously used for that.
Thanks in advance.
Comments
Let me know if that works for you or not.
No, the arrow falls exactly the same, when it hits the ground the lowest density part suffer more impact than the one with a higher density.
Are joints used in the orx integration?
I found some math on the internet to achiev the behavior (haven't implemented yet), but I was hoping to get it working automatically =x
EDIT:
Tried applying a force myself, the arrows keep rotating around the center of gravity. Going to try some more alternatives later.
The most straightforward way of doing this would be to orient the projectile so that its orientation is always tangential to its velocity. Like this: http://www.box2d.org/forum/viewtopic.php?f=3&t=3577
Another approach, a bit more complex, would be the "arrow in flight" paragraph of this tutorial: http://www.iforce2d.net/b2dtut/sticky-projectiles
And as Erin Catto explains it in the first link I mentioned, in vacuum there's conservation of angular momentum and your object won't start turning on its own: http://en.wikipedia.org/wiki/Angular_momentum
PS: And yes, joints are implemented and listed in both the wiki and CreationTemplate.ini.
I tried to implement the ifroce2d site had (I had already found and read that post), but couldn't get it wrong, my guess is that the apply force wouldn't be very easy to implement on orx.
I managed to get the effect I wanted by changing the angular velocity when the as resulting force starts pointing down. When the object rotation is near enough to 0.5*pi I set the angular velocity to 0.
What would be the issue with the force?
Glad you have it working. I think I'd still go with a simple SetRotation though.
The apply force requires you to pass the point you want, but i can't really find the right way to use it.
That's not entirely correct: if you don't pass it a point, the center of mass will be used, which, in turn, shouldn't result in any torque.
Well today I got my notepad and start doing some math, I found what I needed, which was of course, incredibly more simple than I realized at first.
All I wanted was the arrow pointing to the its force result, so I get the vector, gets the pointing angle, normilize it (so all my angles are between 0 and 2 pi) and set the rotation to it.
This does the trick, at least until the arrow hits something, but in this case I just turn the code off.
Thanks a lot for all the help.
EDIT:
Can you point me to an example or to the API of adding joints with code? My best finding reading the API was orxBody_AddJoint but this uses and orxBody, which I suspect is internal to an orxObject.