Page 1 of 1

Best practice for fixing body's rotation?

Posted: Sat Jan 10, 2009 1:30 am
by pufuwozu
Hey everyone!

I've been looking at LOVE for a little while now but I haven't been able to find the preferred way to disable my character from rotating with physics.

At the moment I have something like this in my update function:

Code: Select all

function update(dt)I could 
   world:update(dt)
   body:setAngle(0)
   body:setSpin(0)
end
This just doesn't seem like the best solution. Wouldn't it be possible for the player to become stuck inside another object using this method? Like so:
Image

This Box2d forum post mentions, fixedRotation which seems to be the best way to do this.
http://www.box2d.org/forum/viewtopic.php?p=11428#p11428
(The API says "Useful for characters.")
http://linuxuser.at/elements/doc/box2d/ ... 9d76b6e3ea
But as far as I can tell, LOVE doesn't include a binding for fixedRotation.

Maybe the way I'm already doing it is fine and I'm just being paranoid. For anyone that has solved this problem, how are you doing it? For any LOVE developers, how should I do it?

Re: Best practice for fixing body's rotation?

Posted: Sat Jan 10, 2009 5:45 am
by Tabasco
I dealt with this in my lander game, but it's really a minor issue in that context.

First, I always draw the ship in the same orientation and since it can only hit the ground or the landing pad, which ends the game, I reset orientation in my resetGame() function.
If you're hitting frequently and under circumstances that might cause your object to rotate, you might try putting it in your collision code.
See where the hit occurs, what the current rotation is, what the positions of the objects are, and adjust accordingly.

It might help to know a little more about what you're trying to do.
I really only used physics at all in my game because it made the thrust element really easy, but the physics engine is oblivious to the asteroid field.

Re: Best practice for fixing body's rotation?

Posted: Sat Jan 10, 2009 7:06 am
by pufuwozu
The goal is to make a platformer/sidescrolling game, sorry for not saying that before. I'm hoping to have physics as part of the game element.

By collision code do you mean in the world's collision callback? I guess that could work if I use a bit of maths to figure out where to put the player without putting it inside another object. That seems like a lot of work just to stop an object from rotating. Good idea but I think I'll only do that if I can't find another solution.

Also, is my assumption above correct? Where setting the angle and the spin each update could create a scenario where the player gets stuck? I've tried to simulate it but it's quite hard to tell if it's working or not.

Thank you for your help!

Re: Best practice for fixing body's rotation?

Posted: Sat Jan 10, 2009 3:57 pm
by rude
Added to task list.

Re: Best practice for fixing body's rotation?

Posted: Thu Mar 26, 2009 3:23 am
by machee
rude wrote:Added to task list.
Does that mean you're going to add support for Box2D's FixedRotation flag?

http://www.box2d.org/wiki/index.php?title=B2BodyDef

EDIT: I just noticed the mention of FixedRotation at the end of the original post, so I have to assume, of course that's what you meant. Thanks for LOVE!