Wheels visually look like they're slowing down

Discuss issues specific to the Flash/AS3 port of Box2D
Posts: 7
Joined: Thu Jul 23, 2009 2:15 pm

Wheels visually look like they're slowing down

Postby GroZZleR » Sun Jan 15, 2012 8:06 pm

I'm having an issue where my wheel's sprite begins to visually look like it's slowing down after reaching a certain speed. I imagine what's happening is that the rotation is so fast that its eventually completing 1.00000001 full rotations a frame and thus looks very slow. If I slow the vehicle down under a certain speed threshold, the wheel looks super fast again.

Code is as such:

Code: Select all

sprite.rotation = (body.GetAngle() * 180 / Math.PI) % 360;

Has anyone come up with a solution for this? It's really killing the visual look of the game.

irresistible force
Posts: 1991
Joined: Tue Jun 24, 2008 8:25 pm
Location: Tokyo

Re: Wheels visually look like they're slowing down

Postby irresistible force » Mon Jan 16, 2012 1:42 am

I don't know about Flash but in the C++ version there is an upper limit on the angle a body can rotate in one time step.
It could be that you are hitting that limit... check the b2_maxRotation value here: http://code.google.com/p/box2d/source/b ... Settings.h

Posts: 266
Joined: Sun Oct 25, 2009 3:28 am

Re: Wheels visually look like they're slowing down

Postby jayther » Mon Jan 16, 2012 2:53 am

Yes, there is a setting in flash where you can change the upper limit of how many times a body can rotate (it will be in Box2D/Common/b2Settings.as).

If you don't want to change the upper limit (maybe because you actually want it to go that fast), you can check the angular velocity of the rotating bodies (the wheels) to see if it goes faster than a certain threshold speed (ideally, the speed that makes it look like it's going really really fast before the angular velocity makes it look like the wheels are going slow). If it's slower, then do the normal angle thing. If it's faster, do some other trick to make it more visually appealing. You can get a body's angular velocity with "body.GetAngularVelocity()" (which returns a Number value). You can do something like this (pseudocode):

Code: Select all

if (angularVelocity < visualThreshold) {
   sprite.rotation = (body.GetAngle() * 180/Math.PI) % 360;
else {
   sprite.rotation += (visualThreshold * 180/Math.PI) % 360;

Hope this helps.

Return to “Flash”

Who is online

Users browsing this forum: No registered users and 1 guest