Jump to content
  • Advertisement
Sign in to follow this  
Koshmaar

Wheel motion back and forth

This topic is 3611 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok guys, so I'm reinventing the wheel ;-) Waterwheel, to be more precise, inside of which players may run in a hamster like way. It all works: they run, it accelerates, speeds up, there's speed limit etc. etc. but the one thing I've been banging my head is back and forth motion. Apart from hacky hacks, I have no idea how one could implement it (and to tell the truth, hacks didn't work either). By back and forth motion, I mean when the player leaves the wheel, it slowly decelerates untill it stops, and then moves the other way a little, and stops again etc. untill both acceleration and velocity come down to zero, and whole wheel stops.

void Waterwheel::Update()
{

WheelForce = 0;
	
if( PlayersUsingCount > 0  )
{
	
  for (i = 0; i < PlayersUsingCount; ++i)
    {
      if (PlayerAtDestination)	
        WheelForce += PlayersUsing.Velocity.x;
			
    }								
}		
		

WheelAcceleration = WheelForce / WheelInertia;
		
		
WheelSpeed += WheelAcceleration * deltaTime;
				
if (WheelSpeed > WheelMaxSpeed)
  WheelSpeed = WheelMaxSpeed;
			
if (WheelSpeed < -WheelMaxSpeed)
  WheelSpeed = -WheelMaxSpeed;
		
Angle += WheelSpeed * deltaTime;

// artificial friction
if (WheelSpeed > 0.01)
  WheelSpeed -= deltaTime * 10;
else
if (WheelSpeed < -0.01)
  WheelSpeed += deltaTime * 10;

}


Any ideas how to implement it? Or links to papers / phrases for google (couldn't find anything relevant).

Share this post


Link to post
Share on other sites
Advertisement
for that to happen there has to be a weight offset from the center of the wheel, or else you won't have that "back and forth" motion you're looking for.

try using rigidbodies, might help.


Share this post


Link to post
Share on other sites
Makes sense.

But it doesn't make sense implementing full scale rigid body simulation for rotating wheel, only to add weight offset and realistic swinging. For me, effect counts, not accuracy.

Any ideas how to implement hack this thing? I'm thinking about a set of if statements checking the relationship between acceleration and velocity, but player's influence breaks the system.


Share this post


Link to post
Share on other sites
If some weight is attached to the rim of the wheel somewhere, the torque (angular force) caused by this weight is l*F*sin(theta), where l is the distance of the weight from the center of the wheel, F is the force, m*g in this case where m is the mass of the weight and g is the standard gravity. Theta is the angle between the force (in this case pointing straight down) and the "moment arm" (line from center of wheel to weight).

So, if you want to hack this, keep track of the angle of the weight from the bottom of the wheel. This will be your theta, so sin(theta) = sin(angle). Then use the force (torque) given by

WheelRadius * Weight * sin(angle)

instead of the force from the players. Unless I messed something up, which is likely :D

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!