- Home /
How to make Pinball functionality?
Hi
Im experimenting with a little Pinball Game in the Unity Physics...
I made a nice little frame, a ball with rigidbody and gravity.
But i cant figure out how to make my flipper and how to add force to the ball when there is an collision.. and give the ball the right velocity and direction..
currently my flipper is just a Cube, and i tried with rotating, i tried adding force to the flipper but with out any luck..
I need an idea :)
Thx
Answer by duck · Feb 10, 2010 at 02:51 PM
For the ball-flipper interaction, you shouldn't need to explicitly add force to the ball. Really you just need to rotate the flipper by adding a short but strong burst of torque to it, while also having it strictly constrained so that it only moves within the small angle that flippers generally do.
You could do all this with a configurable joint, and set it up so that your script just sets the target rotation of the flipper when you press the controls. See this question for more information: "keyboard controlled configurable joint"
If you rotate the flipper at a fast enough speed, the ball will be thrown or rebounded off the flipper appropriately by the physics engine without you having to explicitly apply a force to the ball yourself. You might want to use AddForce for other items around the pinball table such as the springs and bouncers.
If you want the flippers to be the traditional pinball flipper shape, you will need to use a custom mesh imported from a 3d app. You'll probably also want use the MeshCollider component, and have it use this same mesh (or a simplified version) as the collision mesh. You will also need to make sure the flipper model's origin is positioned correctly - i.e. at the centre of where it would be attached to its axle in real life - so that when you apply torque, it rotates around the correct location.
You may also find that you need to decrease the fixed timestep, since in pinball the ball and flippers can move very fast compared with the size of objects that they can collide with. Reducing the size of the fixed timestep means that the physics are calculated with higher accuracy, and so there is less chance of the ball passing right through interpenetrating an object too far to give an accurate response.
Answer by GeorgeRigato · Apr 20, 2011 at 07:54 PM
I'm doing the same experiment to learn somethings about unity.
Some hints I managed to find out:
Don't tilt the table to get gravity. Insted go to Edit / Project Settings / Physics and add the proper gravity to create the effect. in my case the Y gravity remained the same, and I added "-4,21" at Z axis (as the top of my table is in the positive part of Z axis) to create a 45 inclination effect (I think!). So Things of my table don't get messed up with weird X-axis roations
Add the Icy material to the "floor" of your table. The walls are a separate object from my table floor. It will ease so much your ball (pinbal ball please!) movement. In another way, the ball will lose traction, so it will spin less, as a marble ball would in a iced plane. Not the best solution (if there is another one), but it easily solves the problem.
Add bouncy material in everything else inside the table, and the ball. It prevents you from manually adding forces for the collisions. let the Unity do the hard work.
My issues:
The flippers are also killing me. I tried the hinge joint for some days now, but it bounces and passes the max and min angles, so it's kinda goofy. So i saw now the configurable joint hint. But it looks so complicated to setup. The way Duck says it, looked simple. But we gotta do what we gotta do right? If i manage to setup this config joint I'll save it forever.
My ball launcher got a spring joint and a addforce script. The force pulls down the cube, the spring pulls up and collides with the ball. Ball got launched. great! The problem? Well, after the first launch, the spring gets "loose", and the cub do not returns the original position. A little backwards (-Z axis really) and the next launch dont get the same ammount of energy to the ball which gets only half way up the launching tube.
Hope the tips help you.
Cheers.
Answer by erikblue88 · Aug 19, 2013 at 06:42 PM
Maybe you should check these videos:
http://www.youtube.com/watch?v=Yaxb1LhRQ_U http://www.youtube.com/watch?v=fRfbDruTgeA http://www.youtube.com/watch?v=y-sNKwBg60g
wonderful and easy to understand tutorial and the link for downloading the project is under the description. Great stuff!
Answer by user-10673 (google) · Mar 24, 2011 at 01:44 PM
I'm doing my pinball game in unity. So... I had some problems with the ball x flipper interaction.. I added a flipper and it rotates when I press a key (I made a script for it). When I release the key, it goes back to the initial state. Like a flipper should work.. :P I don't know if it will be the right way to explain it, but when the flipper collides with the ball, it just push the ball a bit and the ball stay in the place. (For testing purposes, I set rotation zero in all axis). What I was expecting is that the ball goes rolling in the table after the collision.
Note: I selected the ball in runtime to see the properties, and the rotation is changing in all axis after the collision, but the position doesn't change.
the base of the table is a cube.. with no physic material..
I'm wondering if somebody has a tip for me to try.
This is indeed pretty late reply, but I came across this thread while searching for how to do pinball.
You are not supposed to modify any of the Transform property (position, rotation) directly after it is under RigidBody system. I once rotate my flipper directly like that too, the result is the collision will work but no force will be applied to the ball since you did not put any force into the flipper to begin with.
Change the flipper to hinge joint or something, then make it spin up by applying force. That way the force will be transferred to the ball on collision automatically.
Answer by NejoFTW · Mar 13, 2017 at 06:56 AM
a bit late but... https://www.youtube.com/watch?v=y7WgV8-yfcI
Your answer
Follow this Question
Related Questions
2D 360 degress platformer example needed 0 Answers
How to make pinball flipper 0 Answers
Increase force of JointSpring? 0 Answers
PINBALL: Ball colliding problems 1 Answer
Pinball bumper only works once 1 Answer