recently, just on a whim, I took a stab at making a simple (in theory) Air Hockey game in Unity. I assumed I could just place a puck, paddles, and table, then knock things around.
First issue was the scripting just wasn’t coming together- but that’s another story.
The real issue was, after several hours of working just to get the paddle move around on mouse drag, i found that the physics went absolutely BONKERS.
By “bonkers” i mean if i drag the paddle and hit the puck with anything more than a tiny bit of force, it LEAPS from the table like a rocket, or simply disappears.
Things I tried to fix this:
-turned the physics timestep down from .002 to .0002 (helped a little)
-made the paddle Kinematic (otherwise it too went crazy upon hitting the puck)
-made puck and paddle correct weights in their rigid body roll-outs
I will try to post the actual project very soon, so anyone interested can play around with it, look for errors.
At the moment, it just seems to me that the physics are sucking, which I’ve noticed before. No wonder the coder I’m working with has denounced Unity in favor of another engine.
Then again, in this particular case, it’s probably my error- it just seems to simple to work so improperly unless I “hit a wrong checky-boxy” somewhere, etc.
You didn’t mention what you’re using as colliders for border geometry.
You want it to be rather thick, a simple mesh collider won’t work. Even with increased physics iterations, it’s very likely at high speeds the puck will move past a thin mesh collider in one frame and not register a collision at all.
This is a fact of life with all physics implementations, and not specific to Unity.
If Unity exposes “swept collisions” when they update PhysX, the discontinuous nature of the physics simulation won’t be nearly as much of a problem for games with balls in them.
Maker16- Don’t have the project files with me atm (arg), I’ll look into that coding issue. It actually only works halfway, but I can’t complain since it’s borrowed from another unity poster (can’t seem to find the original post, sorry to the author, all credit to you!)
Quietus- For all the parts I am actually using just simple Unity primitives, no meshes as of yet. They are all fairly thick, too.
Well, as I assumed, human error was some of the issue at least.
Just noticed the “Standard Assets” DragRigidBody script, and gave that a go- MUCH better. I can knock objects around the level with ease, and no crazy-physics.
Actually, it seems quite the opposite now- I can whack an object with a ton of force, and it careens into the wall- then stops. sometimes a slight rebound, but many times just about nothing. Ahhg! And i have the mass set fairly low (.2), so I assume it really should bounce. Even using a sphere- it will go flying at the wall, hit it, and then stop as if velcro-ed to the wall.
Will keep messing around with this…
BTW does anyone have a good pre-made script they wouldn’t mind divulging, just to be used for dragging the “paddle” around, to hit the puck with? I’m having a lot of trouble with the script, figured it would be simpler.
make sure to play with physical materials, masses of the objects, try making something heavier and lighter and see how it goes, play with friction and bouncyness
i made a basic pinball game which was made basically like you said, place a pair of flippers a couple of obstacles and knock things around and it was like that, but you need to tweak a lot the properties of the bodies involved in the game
by the way heres the pinball game if you want to try it in a web player…
That plays very nicely David, playing this felt very much like a real pinball machine although things could be a little faster and forceful to my taste.
Eric- yep, I figure that, but shouldn’t default give at least a close to realistic feel?
Back to the original issue, I have rebuilt the scene with mesh objects from Max, made certain I have the exact right scale/etc, and it’s actually gotten WORSE.
About to start breaking things…
Now, objects fall INTO each other, suddenly- I even tried creating two 1x1x1 default cubes, made them both rigid bodies, made the lower on kinematic, then made the top one fall onto the lower. It goes into the cube about 8cm.
AAHHHG. Going crazy over such a should-be-simple idea.
I have never before noticed things falling “into” each other, and have done several physics tests before, just messing around- does anyone know if I might have bumped a setting or some such to cause this? It’s ridiculous…
The default does give a realistic feel, depending on what you’re doing. A pinball game will need tweaking because you are working on small scales.
Try to keep your models not too much smaller than 1 unit in size, and make sure the min penetration for penalty isn’t too far from .01, and that the physics timestep isn’t too large.
I have a 1meter long by .5meter wide table, and proportionately sized puck and paddle (for the air hockey game). Nothing tiny, just average sized parts…I would think.
The puck and paddle probably are too small, actually. The physics engine doesn’t like small scales, so it’s likely to work better if you scale everything up and then make adjustments so the speed and so on looks right.
cool, will do- specific suggestions on how large to scale up? is there a “rule of thumb”, ie, always at least .5meters, or some such?
I’m happy to make the changes, easy done, however it still strikes me as a bit silly that the engine needs it done. I had thought technology was beyond that
Just wanted to make a final note to any viewers who find this, and a thanks, simply scaling the scene up solved nearly all my problems instantly!
I scaled everything exactly 4x (by setting the “import scale” to .04, since it is normally .01 due to me working in CM in 3dsMax, and Unity is meters).