As you can see, the first object hit with the dagger should have fallen, however it doesnt, and just goes back into standing position. I assume the reason is that the impact calculated by the engine was not high enough to push it over, but from looking at it it should have been.
Another issue is that sometimes the thrown objects bounce of oddly and way too strong.
I wonder if there is something I can do to improve this behavior.
What are the settings on your rigid bodies? It’s possible collisions are happening where the object passes through in between fixed time steps only to collide with the back of the object (causing the strange movement in the wrong direction).
If the collision mode is discrete or continuous, try changing them to continuous dynamic. This will improve collision detection in between fixed time steps for colliding rigid bodies (with some performance cost).
Seems to me that the object penetrated the post and reported a collision behind it also which pushed it back up. You probably need to ignore collisions after the first impact, or at least filter out collisions which occur while the thrown object is moving away from the hit object. Stuff like this is pretty common when working with physics and games.
Although the above advice is great regarding continuous, for a bullet proof approach you will still need to handle the case where it is moving away if you are a perfectionist (for example the thrown object is rotating so it can still technically hit something while moving away from it).
I don’t think it should be necessary but if you want full control over collision and response you probably want Unity - Scripting API: Physics.ComputePenetration which lets you see what Physx would see, without the actual response getting in the way (you need to code that yourself).
Although I’m hoping Keith’s advice is all that’s needed since it’s easier!
Generally we turn off collisions once a collision happens, until it is required again.
This is based on the tried and tested approach used in custom collision detection models (such as the type you would have programmed back in the day for xna/monogame, or mark overmars gamemaker if your old enough to remember when it was called that!).
Essentially your checking once it collides and then moving the position of the object back to the position it was at just before the intersection (otherwise it will clip the object). Naturally with unity we already have a collision detection system so no need to implement this, just need to ignore collisions until collider is required to be active.
since I got such good input here, I’m gonna use this to post my next related question.
Very rarely, maybe in one of 100 cases, this happens:
You see explosions, but there are no external forces added. No physics coding is done on impact whatsoever, just pure Unity physics. Only Box colliders are used.
All RB objects have Collision detection set to Continous Dynamic and Interpolation deactivated.
Any idea what might be causing this and what I can do to prevent ths?
I’m curious what the behavior normally looks like. It doesn’t seem particularly wacky, even in real life throwing something like a knife can ricochet in ways that send it flying more than expected.
I do see a small impulse but that’s probably just physics iteration error. You could try increasing the “Default Solver Iterations” or “Default Solver Velocity Iterations” under Edit/Project Settings/Physics. You can also mess with Rigidbody properties maxDepenetrationVelocity and maxAngularVelocity (or specifically set their solverIterations or solverVelocityIterations properties as well).
If you want to ignore physics from the knife after impact, you can have it switch to another layer that ignores the knife but still interacts with the ground.