- Home /
How do you create a realistic wheel of fortune style prize wheel?
How would you create a realistic wheel of fortune style prize wheel? I'm talking about a spinning cylinder with pegs on the outside and then a flexible stick that hits the pegs to slow it down (the wheel also has friction). The stick bending and then snapping back into place with each peg hit is important. Ideally it would have those suspenseful last peg hits occassionally where you aren't sure at which prize the wheel will stop. I'm not interested in the creation of the wheel so much as the physics behind everything in the scene.
Thanks!
Answer by robertbu · Sep 26, 2013 at 02:18 AM
I ran a quick test and ended up with a wheel that worked well and had those suspenseful last peg hits. My recipe:
Created a flat cylinder for the base.
Replaced the default capsule collider with a mesh collider on the base.
Added a Rigidbody to the base.
Enabled 'Freeze Position' for x,y, and z;
Turned off gravity
Enabled 'Freeze Rotation' for x and z (y still allowed to move).
Added pegs as children. They had colliders, but no Rigidbodies.
Added flipper.
Added Rigidbody to flipper
Added hinge joint to flipper with anchor on the right edge of flipper
Set joint axis to 'Y'
Enabled 'Use Spring' and set Spring to 11 and damper to 1
Added the standard DragRigidbody script to an empty game object.
I'm sure by playing with the settings you can refine this setup even more.
First of all, thanks a ton! This is great.
I have a couple questions for you: 1) What is the point of the mesh collider on the base? The collider isn't actually hitting anything, just the pegs. 2) "Added the standard DragRigidbody script to an empty game object." What does this mean exactly and what is the point of this? 3) $$anonymous$$y biggest problem is speed. The wheel needs to spin quickly and the lots of pegs will be hitting the flipper one after another. Right now the flipper acts great but then if I increase the speed the physics calculations mess up because (I presume) the pegs are jumping into the middle (or straight across) the flipper. I tried using continuous dynamic collision detection, interpolation, and reducing the fixed timestep in the time manager of my project. $$anonymous$$y first 2 solutions didn't seem to do anything but reducing the fixed timestep does help... but doesn't get me to the point of a really fast spinning wheel hitting the flipper a lot. Thoughts?
Again, thanks a million!
amazingly generous solution.
you say it doesn't work at high rotation speeds. expressed in "pegs per second" please tell us precisely when the problem kicks-in
conceptually if it "doesn't work" at high PPS, you will have to add another "mode" when the rotation speed is above that domain.
Robert, for the "high PPS" mode don't you agree it would be best just to have an animation of the flipper sort of "bent back, just out of the way, and shuddering/flickering" as if it is being flicked really quickly and erratically.
then in "high PPS" domain, just turn off the ordinat flipper and replace with the "actually just a flicky animation" flipper.
have a script on the wheel with a line of code that changes from one domain to the other based on the speed
I wanted a collider on the base so that I could grab and spin it. By default a cylinder gets a capsule collider, so if you take a look in the Scene view, a squashed cylinder like this one would have a big sphere part of the collider above the top surface. This sphere would interset the flippers.
As for the speed issue, you've already done the things I would typically suggest. One other thing I did that may have an impact is to drastically reduce the mass of the flipper. I set it at 0.05. You might also set $$anonymous$$in "Penetration for Penalty" in the Physics settings to 0.0.
@Fattie solution to "fake" the high-speed movement should work fine if you get the ti$$anonymous$$g of the transition between "fake" and real movement correct. It's not something I would have though of. As usual his thinking out of the box comes up with a great idea.
Hey guys, you are awesome. Super helpful.
I think my problem was appearing because I was modifying the transform of the wheel in it's update function... 2 rookie mistakes in one. 1) Do not modify the transform of rigid bodies and 2) do not do it in update function. Fixedupdate is where I should add forces.
Anyways, right now I'm just adding an enormous torque at the beginning and I reduced the timestep and things are working awesome. The flipper $$anonymous$$IGHT skip a peg or two when it's spinning around really fast but honestly you can't tell because it's constantly being knocked in the right direction so it's not a big deal. I will definitely consider faking it in the end if I have to but right now it's looking pretty awesome.
Thanks again!
Hope I'll get an answer here ins$$anonymous$$d of starting a new thread. I used the method provided above and I'd like to understand/expand on a few things. I'm still a beginner in Unity so I didn't quite understand the solution for the "high PPS" problem.
And then my biggest problem: how do I check if the wheel (the flat cylinder) is no longer spinning? (so that I can read the score the flipper is on when it stops moving; this of course should happen only after the player has moved the wheel). I've made some empty objects with box colliders so that, when the wheel is no longer rotating, the one colliding with the flipper would give the correct score.
Thanks!
Your answer
Follow this Question
Related Questions
Bend a 2D sprite using physics. 1 Answer
how can i make a joint like this in unity? 2 Answers
Bend 3d object (Mesh) at Runtime 2 Answers
2D Shader that bends vertices? 3 Answers
Bending a stick problem (Probably easy for an intermediate programmer) 0 Answers