• Advertisement
Sign in to follow this  

Spinning prize wheel

This topic is 1061 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

I'm working on a prize wheel that has 12 wedges. The wheel accelerates for a few seconds before it begin decelerating to a wedge that is known ahead of time. The wheel is decelerating but it's not stopping on the correct location. I'm using the following to determine the stopping place:

spinTo = (360 * 3) -  (mStopPosition * 30.0f) - Wheel::GetDegree();       //wedges are 30 degrees apart  (360/12)

 

I'm determining the deceleration with:

acceleration =  -( Wheel::GetVelocity() * Wheel::GetVelocity() )/(2 * spinTo);      // accerleration = - v0^2 / ( 2 * s )

 

And rotating the wheel each frame with:

HandleRotation(Wheel::GetDegree(), Wheel::GetVelocity(), acceleration, dt);

 

My rotation code is as such:

void HandleRotation(float degree, float velocity, float accel, float dt)
{
    velocity += (accel * dt);
    Wheel::SetVelocity(velocity);

 

    degree += velocity * dt;
    
    RotateWheel(degree);
}

 

The wheel decerlates until it's velocity is 0 at which point I expect the wheel to stop at mStopPosition. Does anyone have any idea as to why the wheel is not stopping at the expected location?

 

Thanks!

Edited by ivincent

Share this post


Link to post
Share on other sites
Advertisement

The kinqmatic equations for this problem are xf=xi + vi * t + 0.5*a*t2 and vf = vi +a*t

 

You know v_f=0, you know v_i is whatever you want it to be, you know x_f, you know x_i, and you can set t to whatever you want.

 

You can then get the correct acceleration algebraically: a=(xf-xi-vi*t)/(0.5*t2)

 

Then, you can get the velocity whenevery you want by pluggin in the current time value and acceleration to: vf = vi +a*t

 

You can also get the current position by plugging in the current time and velocity to: xf=xi + vi * t + 0.5*a*t2 (It's a bad idea to go off of your modified velocity, because you can't predetermine it.)

 

 

 

Alternatively, if you want acceleration and deceleration, you can use the modified kinematic equations involving jerk, snap, etc, or you can use the equations for bezier curves, but that's harder. Or you could take the easy way and just have it accelerate for a few revolutions and then slow down.

Share this post


Link to post
Share on other sites

The kinqmatic equations for this problem are xf=xi + vi * t + 0.5*a*t2 and vf = vi +a*t

 

You know v_f=0, you know v_i is whatever you want it to be, you know x_f, you know x_i, and you can set t to whatever you want.

 

You can then get the correct acceleration algebraically: a=(xf-xi-vi*t)/(0.5*t2)

 

Then, you can get the velocity whenevery you want by pluggin in the current time value and acceleration to: vf = vi +a*t

 

You can also get the current position by plugging in the current time and velocity to: xf=xi + vi * t + 0.5*a*t2 (It's a bad idea to go off of your modified velocity, because you can't predetermine it.)

 

 

 

Alternatively, if you want acceleration and deceleration, you can use the modified kinematic equations involving jerk, snap, etc, or you can use the equations for bezier curves, but that's harder. Or you could take the easy way and just have it accelerate for a few revolutions and then slow down.

 

I'm using v0^2 / ( 2 * s ) to determine the correct deceleration and the spinTo amount is also correct. What is it about my code that is causing incosistencies in the spin stop location?

Share this post


Link to post
Share on other sites

 

...

I'm using v0^2 / ( 2 * s ) to determine the correct deceleration and the spinTo amount is also correct. What is it about my code that is causing incosistencies in the spin stop location?

 

 

I didn't look too closely at the equations, but you're basing your next degree off of your modified velocity value, which changes during any amount of time at all. Like I said, if you wanted a predetermined end location, then you should base the position, or degree, off of an equation with the only variable being time. Thats where the xf=xi + vi * t + 0.5*a*t2 equation came in.

Edited by SimLeek

Share this post


Link to post
Share on other sites

I figured out the problem. My math was correct but the degree of rotation was being changed in a separate section of code that I wasn't aware of at the time. That was causing the inconsistency. Thank you for you help.

Share this post


Link to post
Share on other sites

Ok when I use the following equation the wheel stops correctly:

acceleration =  -(Wheel::GetVelocity() * Wheel::GetVelocity())/(2 * spinTo);

 

hower when I try to find the deceleration given a time I get inconsistent results:

acceleration = (2 * spinTo - (2 * Wheel::GetVelocity() * time))/(time * time);

 

 

Here's the rotation code that is called every frame:

void WheelSpinEffect::HandleRotation(float degree, float velocity, float accel)
{
    float oldVel = velocity;
    float dt = 1.0f/GraphicsDevice::GetRefreshRate();
        
    velocity += (accel * dt);    
    degree += (oldVel + velocity) * 0.5f * dt;
    
    RotateWheel(degree);
   
    Wheel::SetVelocity( velocity );
}

 

 

Does anybody know what this might be?

Edited by ivincent

Share this post


Link to post
Share on other sites

hower when I try to find the deceleration given a time I get inconsistent results:

 

Why are you trying to find the acceleration based on time? (Really, I have no idea what you're trying to do with that.)

 

Also, your position calculation is still innacurate and will build up error over time. The only variable you should be basing your time variant variables on is time.

 

 

 

Edit: did you change spinTo to reflect that it was time variant? Or do you want acceleration to change throughout the equation to make the wheel harder to follow?

Edited by SimLeek

Share this post


Link to post
Share on other sites

Why are you trying to find the acceleration based on time? (Really, I have no idea what you're trying to do with that.)

 

I'm trying to find acceleration based on time because I need to know how much decleration to apply to the wheel to make it stop at the correct location in 5 seconds. Is this not the correct way to determine this? I'm using the equation a = (2 ?s – 2 v1 ?t) / (?t)2   where s is spinTo.

 

 

 


Also, your position calculation is still innacurate and will build up error over time. The only variable you should be basing your time variant variables on is time.

 

Why is the position calculation innacurate? I'm using Verlet integration to determine the position based on the average velocity as explained in this article http://lolengine.net/blog/2011/12/14/understanding-motion-in-games.


 

Edit: did you change spinTo to reflect that it was time variant? Or do you want acceleration to change throughout the equation to make the wheel harder to follow?

SpinTo and acceleration never change. They remain constant after being set initially.

 

I am not calling both of these just one or the other:

acceleration =  -(Wheel::GetVelocity() * Wheel::GetVelocity())/(2 * spinTo);

acceleration = (2 * spinTo - (2 * Wheel::GetVelocity() * time))/(time * time);

 

The first works correctly and the wheel stops as expected. The second does not and I need to find out why.

Edited by ivincent

Share this post


Link to post
Share on other sites

Well, first off, you can't vary time, acceleration, and final position at the same time. They're dependant on eachother. However, you can vary final position and time, or acceleration and time. (Note: acceleration is always constant for objects that aren't being pushed, so it might be best to just select final position and let the wheel go for as long as it wants.)

 

Edit: whoops, looks like I assumed things. That wasn't exactly what you were doing.

 

 

 


Is this not the correct way to determine this? I'm using the equation a = (2 ?s – 2 v1 ?t) / (?t)2 where s is spinTo.

 

Well, the equation is correct, but it never included v_final, so the velocity at the end could be non-zero and the wheel could continue spinning.

 

 

 


Why is the position calculation innacurate? I'm using Verlet integration to determine the position based on the average velocity as explained in this article http://lolengine.net/blog/2011/12/14/understanding-motion-in-games.

 

Whoops, you're right. Still, I think it's overcomplicating things to use Verlet integration when you can just use algebra to get the positions directly. This would be more useful if you had velocity being changed by many different things or controlled by the player, and you wanted it to stay accurate with writing code for all the different cases. Since you're only finding the velocity and position of a wheel that's only spun once, you only need to calculate it directly.

 

If you were making something that calculated velocity and position in general from acceleration, then that would be perfect. It's also good if you want to be let the player grab the wheel and add some velocity to it.

 

 

 


The first works correctly and the wheel stops as expected. The second does not and I need to find out why.

 

Ah, yeah. Your first equation takes a kinematic equation, sets vf=0, and then solves for a; Your second one sets time, but not vf.

 

If you wanted different spining_times and resulting accelerations for the wheel, you could use vf = vi +a*t and set a=-vi / t. Or, you can use spin_degrees=((vi+vf)/2) * t and set t= 2*spin_degrees/vi. You can't set both a and t though.

Edited by SimLeek

Share this post


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

  • Advertisement