Wheel motion back and forth

Started by
2 comments, last by Lord Crc 15 years, 4 months ago
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).
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.


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.


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

This topic is closed to new replies.

Advertisement