Wheel motion back and forth

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

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 on other sites
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 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 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

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

1. 1
2. 2
3. 3
Rutin
23
4. 4
5. 5
khawk
14

• 9
• 11
• 11
• 23
• 12
• Forum Statistics

• Total Topics
633653
• Total Posts
3013164
×

Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!