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..
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.
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.
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.
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.