- Home /
Rigidbody trapped in collider after collision
I am currently attempting to make an object collide with another and subsequently pass through that object. This implementation below works fine for objects up to a certain speed at which point they get trapped inside the other collider and struggle to pass through but cannot move even though they retain their velocity.
The collision is being detected with ray casting and I've confirmed it is colliding with the target as expected when it gets stuck.
Any help is appreciated. Thanks for your time.
if (pierce)
{
Physics.IgnoreCollision(GetComponent<Collider>(), cb);
//Stop from rotating after hitting the object
rb.freezeRotation = true;
rb.freezeRotation = false;
//reset velocity
rb.velocity = originalDirection.normalized * originalDirection.magnitude;
//reset look rotation
rb.rotation = Quaternion.LookRotation(rb.velocity);
}
Answer by mlnczk · Jan 02, 2019 at 10:13 AM
So you got two objects both with colliders and you want them to pass through without colliding? If so then set one collider to be "Is Trigger" and if you want to do something while they touch their colliders you got unity's method OnCollisionTrigger(). If you got some setup that allows them to go through or doesnt depends on option then you can mark it as trigger by code simply by collider.isTrigger = true/false;
Hello $$anonymous$$inczk, thanks for the reply.
However for my particular issue it works with the above implementation for my colliders and triggers how I want it to and I'm trying to deter$$anonymous$$e why it begins to fail when the object is going faster because it still shows that it registers the collision and disables runs through the aforementioned code but for whatever reason it just stays inside the object afterwards ins$$anonymous$$d of passing through normally.
Is there something else I'm unaware of that the Physics.IgnoreCollision portion is incapable of stopping faster moving objects?
Edit: spelling
Hi shoopuff! If you dont want those object to collide ever then go to Edit - Project Settings - Physics. You have squared with marks you can setup over there possible collision. Just uncheck boxes between those two objects so the engine knows whether to calculate collisions or not. Its also very good for optimalization.
Unfortunately I don't want these objects to never collide and I'm aware of the layering system that Unity has to prevent them from doing so and am actively using it already. I want these objects to only stop colliding if they have that boolean set (Pierce) otherwise they should collide normally.