Object rotation

Nov 8, 2010 at 7:26 PM

First of all, thanks for your work on this very interesting library.

The main object in my game is a ball with a faux-3D effect (circular gradient in the upper corner). However, when the ball hits static objects, it starts to rotate, which makes the faux-3D look a bit weird. Is there any way to keep the behavior intact while keeping it from rotating?

I read on the forum that I could try setting MomentOfIntertia to float.MaxValue but this doesn't seem to fix my problem - however I think that is more of a fix for when the object is hit by another flying object.

Thanks!

Coordinator
Nov 8, 2010 at 7:53 PM

Yes, this is something that has changed in the underlying physics engine (Farseer 3) and I think it is exposed in more recent change sets in Farseer 3.

When I last looked, there wasn't a SetMassData method exposed but I think it is there now. If you're interested here is my post in the Farseer forum - http://farseerphysics.codeplex.com/Thread/View.aspx?ThreadId=230205

Soon I hope to get the latest changeset from farseer and integrate it into the Physics Helper, it looks like there has been a lot of fixes/additions in the past weeks.

Nov 8, 2010 at 8:06 PM

Thanks for your quick reply. I'll be keeping an eye on this project for said updates. 

In the meantime I was hoping to be able to access the Farseer settings through the PhysicsControllerMain, but controller.PhysicsObjects throws an exception when I try to access it (same goes for the Simulator property).

Might also be worth mentioning that I'm developing on Windows Phone.

Coordinator
Nov 8, 2010 at 8:30 PM

Make sure to wait for the Initialized event before you try accessing these properties. Here is some sample code (also note there is a Demo in the full source code download under Change sets).

void ucMainGame_Loaded(object sender, RoutedEventArgs e)
{
    if (DesignerProperties.GetIsInDesignMode(this))
        return;

    _physicsController = cnvGame.GetValue(PhysicsControllerMain.PhysicsControllerProperty) as PhysicsControllerMain;
    _physicsController.Initialized += new PhysicsControllerMain.InitializedHandler(_physicsController_Initialized);
    _physicsController.Collision += new PhysicsControllerMain.CollisionHandler(_physicsController_Collision);
    _physicsController.TimerLoop += new PhysicsControllerMain.TimerLoopHandler(_physicsController_TimerLoop);
}


void _physicsController_Initialized(object source)
{
    _playerPaddle = _physicsController.PhysicsObjects["paddlePlayer"];
    _cpuPaddle = _physicsController.PhysicsObjects["paddleCpu"];

    _playerPaddle.BodyObject.LinearDamping = 30.0f;
    _cpuPaddle.BodyObject.LinearDamping = 1.0f;
}