Physics problem

edited June 2013 in Help request
Hi there, I am trying to use physics for the first time with orx.

So far I have drawn a basic closed room with walls, the ground and a sphere. I wanted the sphere to roll around the room as if it was a snooker ball.
But the result I got is that the ball start going one direction and back, non-stop, as if there a force was being applied in to one direction then another force was applied in the invese direction.

Here is the code section (I have tried apply force, apply torque and apply impulse, they all had the same result);:
orxVECTOR force;
    force.fX = 0.0; //orx2F(-10.0);
    force.fY = -10.0;
    force.fZ = 0.0;
    grid->beginPos.fZ = -0.1;
    orxObject_SetPosition(sphere, &grid->beginPos);
    orxObject_ApplyForce(sphere, &force, orxNULL);
    orxObject_ApplyTorque(sphere, 50.0);
    //orxObject_ApplyImpulse(sphere, &force, orxNULL);

And the ini:

Texture       = ../../art/sphere.png
Pivot = left top

Type        = sphere
SelfFlags   = 0x0001; <= This defines our collision flags
CheckMask   = 0xFFFF; <= This defines the collision mask that will be testing on other objects
Solid       = true

PartList    = Basic_Sphere_FullPartList
Dynamic     = true 
AllowSleep  = false

Graphic = Basic_Sphere_Graphic
Alpha   = 1.0
Body    = Basic_Sphere_Body

Graphic         = Ground_Graphic
Alpha           = 1.0

Texture       = ../../art/ground_colored.png
Pivot         = left top

Type        = box
SelfFlags   = 0xFFFF; <= This defines our collision flags
CheckMask   = 0x0001; <= This defines the collision mask that will be testing on other objects
Solid       = true;

PartList    = Wall_Body_FullPartList
Dynamic     = false
AllowSleep  = false

Any insights?

Thanks in advance.


  • edited June 2013
    Hi Knolan,

    Sorry for the delay but I'm currently in the process of moving from San Francisco to Montreal and don't have much computer time if any.

    First thing: you should center your pivot on your ball object.
    Second thing: you shouldn't apply both a torque and a force, it's unnecessary and they might either work against each other or combine into undesired effects.
    If you push your ball with a force, frictions will make it roll.
    Third thing: you can use literal names to define your SelfFlags/CheckMask. More info here.

    Lastly, I'm afraid you'll have to ask also on the Box2D forum for advanced support as I'm no Box2D expert. Orx mostly forwards the info to Box2D and let it to its things. Setting up a physical simulation that behaves exactly the way the user wants is notoriously hard, and it's not just a Box2D thing either.

    Good luck! :)
  • edited June 2013
    Thanks for the reply, I couldn't get it running with apply force (with the pivot it got better, but not quite what I wanted), but the I could get the behavior I wanted using set Gravity.

    EDIT: Lol, one second later I got it right, thanks a lot.
  • edited July 2013
    My pleasure! Glad you got it working, as I said, physics-setting matters are always a bit tricky (and a lot of trials&errors)! ;)
Sign In or Register to comment.