Box2D Forums

It is currently Mon Apr 21, 2014 5:42 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Sun Jan 15, 2012 8:06 pm 
Offline

Joined: Thu Jul 23, 2009 2:15 pm
Posts: 7
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:
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.


Top
 Profile  
 
PostPosted: Mon Jan 16, 2012 1:42 am 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1769
Location: Tokyo
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


Top
 Profile  
 
PostPosted: Mon Jan 16, 2012 2:53 am 
Offline

Joined: Sun Oct 25, 2009 3:28 am
Posts: 258
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:
if (angularVelocity < visualThreshold) {
   sprite.rotation = (body.GetAngle() * 180/Math.PI) % 360;
}
else {
   sprite.rotation += (visualThreshold * 180/Math.PI) % 360;
}

Hope this helps.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Yahoo [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group