Best practice for fixing body's rotation?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
pufuwozu
Prole
Posts: 3
Joined: Fri Jan 09, 2009 5:52 am
Location: Brisbane, Australia

Best practice for fixing body's rotation?

Post 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?
User avatar
Tabasco
Citizen
Posts: 72
Joined: Tue Dec 02, 2008 5:04 pm

Re: Best practice for fixing body's rotation?

Post 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.
User avatar
pufuwozu
Prole
Posts: 3
Joined: Fri Jan 09, 2009 5:52 am
Location: Brisbane, Australia

Re: Best practice for fixing body's rotation?

Post 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!
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: Best practice for fixing body's rotation?

Post by rude »

Added to task list.
machee
Prole
Posts: 5
Joined: Tue Mar 03, 2009 12:35 am

Re: Best practice for fixing body's rotation?

Post 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!
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 211 guests