Weird physics issue

Hi,

i’ve got a really weird physics issue. I’ve got terrain mesh and fast moving block (just a cube) in a test level. The cube velocity is pretty high - speed/velocity vector length is about 160 - and on some points hes passing though the terrain object. Of course i know this happens sometimes, so i raised the physics iteration to 100 and both colliders use continuous/continuous dynamic collison. Terrain also has a kinematic rigidbody attached. And heres the funny point, i get a message the two objects are colliding. So why is the block still going through the terrain mesh and what can i do about it?

Greetz, the chicken

Edit: Oh and yes, i know my english is awful. Sorry for that :wink:

First:

  1. why does the terrain have a rigid body? it shouldn’t unless you’re planning to move it

  2. second, how are you moving said cube? what is your code? How you move it really is important.

  3. tried continueous dynamic collision options etc? see docs.

  1. I dont know, didn’t have any more ideas and thought, maybe a kinematic rigidbody will help :smile:
  2. I’m moving it by applying a force to the rigidbody when i press a key. whenever it hits another object, no more forces are applied to avoid that im the one pushing the object through the other collider.
  3. As i said, yes i tried continous dynamic and it doesn’t help at all.
  1. what size is the mesh and cube in unity units? if they are under 1, you probably could use scaling everything up a little.

  2. remove the rigid body and kinematic from the terrain, it is pointless.

  3. post some code. Preferbly all of your setup code for the block and terrain and the code for moving the block.

The meshes are actually scaled up quite a bit. The cube is scaled up to 8x8 and the terrain is 750x750.

Code is pretty simple right now:

if (Input.GetKey(ForwardKey))
        {
           if (!Colliding)
           {
                VV = this.rigid.velocity;
                VV.y = 0;
                float Speed = VV.magnitude;
                CurrentSpeed = Speed;
                float EvaluatedMultiplier = Mathf.Clamp01(AccelerationCurve.Evaluate(Mathf.Clamp01(Speed / ForwardForce.x)));
                AddedForce = ForwardForce * EvaluatedMultiplier;
                this.rigid.AddRelativeForce(ForwardForce * EvaluatedMultiplier, ForwardForceMode);
            }
        }

Range of the curve is between 0 and 1.
ForwardForce is 100 i guess.
And as i already mentioned, unity is even telling me the two objects do indeed collide. But the cube doesn’t stop. But for something like a racing game (thats what im prototyping right now) it sucks, if u just have velocities around 10 or something like that. Wouldn’t look fast at all.

oh right. I bet you’re not doing this in fixedupdate are you?

Physics have to be done in FixedUpdate.

Well, of course im doing this in fixed update. Otherwise that would be an obvious reason. I know, this kind of problem can occur. The only thing thats strange is, im writing it to console if the cube collides with another object. And he does, but its still going straight through it. Could it be possible, that this is because of the MeshCollider? Read somewhere it is like a pretty thin skin like collider, instead of a thick one (which would be what i need).
Btw thx alot for your help already :wink:

Does the terrain and the block both employ mesh colliders?

Right now they do, but it also happens with a box collider. Tried it already. I’d guess it really is, that physx can’t handle the velocity at this point. I don’t have any other explanation right now.
Maybe i’ll try to compansate it myself in a script somehow, because the OnCollisionEnter still gets called, so its probably the best way.

Don’t do mesh to mesh collisions, change that right away. You keep banging on about OnCollisionEnter still gets called, but I’m ignoring it because it 100% does not matter. Just because it collides it does not mean it is able to respond to it properly in the collision engine. Ignore that.

  1. make sure you use a collision box not a collision mesh for the moving object. Don’t argue :slight_smile: Later you can change it to a convex mesh if you wish but for now, make it a box collider.

  2. Ensure the mass, bounce, friction etc are all at 1.0 for the sake of testing.

  3. Does it occur when the object bounces or in any way responds to other collisions, or when you’re just using physics forces yourself? If it is from a bounce, its a separate issue.

  4. does the terrain use extremely low polygons where it passes through? if it does, just subdivide it a bit in your modelling package and try again. This is because physx craps out on really large polygons.

  1. Yeah, was just for testing.
  2. Thats what its set to right now.
  3. Not particularly larger than any other polys in the mesh.
    BUT 3. and

gave me an idea. Because indeed it doesn’t seem to happen now that i thought about it, without a force applied. So a simple trigger with small range, stopping the script from applying any force at all, or something similar might help. I’ll try it when im back in a few days.
Thx a lot for your help, even if its not the reason, you got me closer to the reason.

That seems like an awful workaround, I know unity for sure is able to fire all sorts of cubes at meshes without them going through - even really fast so I’m wondering whats set up wrong. I’m interested in this because my own game is heavily physics based. I have 4 simultaneous user-made worlds which rotate with 32 balls that must not fall through.

I generally have a big interest in physics, its great fun to mess with. I hope you get it sorted out. Trying to think why it’s behaving so odd for you.

I’ve tried the same thing again, but instead of the terrain i used a simple cube with a box collider. And i smashed my cube right through it, although i needed a way larger velocity (about 2500). So it seems my world is simply too big :smile: Solution would be, scaling everything down and adjust my forces i guess. Not quite sure if it will help at all.

tried http://www.unifycommunity.com/wiki/index.php?title=DontGoThroughThings ?

it prevents things from ever going trough things. No matter how fast it is.

Ah nice, thanks. Had exactly the same idea when sitting in the train yesterday :smile:
I’ll try it as soon as possible (which will probably this evening).