Objects Get Knocked Through Walls

My current project has quite a few objects being knocked around in almost comical fashion with rather heavy use of force on rigidbodies, but there’s been an issue that keeps on throwing a wrench into things.

Specifically, stuff keeps being knocked through things. OK, that isn’t very specific, but still. As things currently stand, I have a lot of small quick-fixes in place, but most of them are the sort of fix that would be extremely noticeable to a player.

There’s currently only one main concern remaining that is easily noticeable, however. The invisible walls at the edges of the level. I’ve even tried increasing their thickness by 1000x, but sadly things keep getting knocked past the wall entirely and trigger the emergency respawn I’ve coded in.

Is there any sure-fire way to stop things from passing through invisible walls?

Colliders are the thing you should use for this concern......[OnTriggerEnter][1] by using colliders you can easily stop ghost like behave of your objects.... Don't forget to mark the answer if found useful.....cheers From INDIA........ [1]: http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnCollisionEnter.html

Just saying "use OnTriggerEnter" isn't helping at all. If it was that obvious, I wouldn't be asking. Specifically how does one use OnTriggerEnter to prevent ghost-like behaviour? (Everything had a collider already, but nothing is currently using OnTriggerEnter because I have no idea why I would use OnTriggerEnter)

1 Answer

1

This question comes up fairly regularly in various forms. The last one I remember was here:

http://answers.unity3d.com/questions/420482/fast-physics-for-a-pool-game.html

There is no magic bullet. The problem is that if things move fast enough the moving object can skip past a collider…be on one side of it in one frame, and completely on the other side in the next. There are a variety of suggestions:

  • Goto to Edit/Project Settings/Time and reduce the Fixed Timestep it is 0.02 by default, so set it to 0.01 or even smaller. Note this is computationally more expensive.
  • Set Collision Detection Mode to Continuous.
  • Directly limit the maximum velocity in the Rigidbody.
  • Add a second set of walls outside the first ones.
  • Use the properties of the containing space to detect when an object is beyond range and correct the situation.