Heavier part on an object.

edited September 2013 in Help request
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

  • edited September 2013
    I've never really used it myself, but I believe what you're looking for is the Density attribute of a part. That's how Box2D determines the center of mass of a body.

    Let me know if that works for you or not. :)
  • edited September 2013
    Thanks for the reply.

    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.
  • edited September 2013
    Well, in order to have your projectile re-orient itself in flight, you need to fake air resistance.
    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. :)
  • edited September 2013
    Thanks for the answer.

    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.
  • edited September 2013
    Knolan wrote:
    Thanks for the answer.

    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.

    What would be the issue with the force?
    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.

    Glad you have it working. I think I'd still go with a simple SetRotation though. :)
  • edited September 2013
    Mostly the same problem I am having whenever I try using the apply force method the arrow go rotating around itself insted of flying straight.

    The apply force requires you to pass the point you want, but i can't really find the right way to use it.
  • edited September 2013
    Knolan wrote:
    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.
  • edited September 2013
    Well, I can post a screen shot/code here, maybe I screwed up the center of mass thing.

    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.
    static void test3(){
    
        orxVECTOR force;
        orxObject_GetSpeed(arrow, &force);
        orxObject_SetRotation(arrow, normalizedRadians(orxMath_ATan(force.fY, force.fX)));
    
    }
    

    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.
Sign In or Register to comment.