IEnumerator OnTriggerEnter(Collider other)
{
triggerPos = transform.position;
//rb.collisionDetectionMode = CollisionDetectionMode.ContinuousSpeculative;
rb.isKinematic = true;
for (int i = 0; i < 30; i++)
{
yield return new WaitForEndOfFrame();
}
transform.position = triggerPos;
}
What i’m trying to achieve here is so as soon as rigidbody(with a trigger colldier) hits any collider it should become kinematic so that it instantly stops. But most of the time it all takes place only after it passes through the object. It happens too late, and i even added a delay to roughly half a second to update position back to the moment of trigger in case there’s maybe some inertia left or idk what else. I tried everything except setting Fixed Timestep to some lower value(i guess it would be a terrible solution even if it would work).
Is there anything that be done?
OnTriggerEnter will happen on the first physics update in which the two colliders are intersecting. Unfortunately because Unity uses a discrete-timestep physics simulation, this means that the objects may be significantly overlapping by the time you see it. (e.g., in the previous simulation frame, they were not overlapping, but in this frame, they are halfway through each other). It of course depends on the velocities of the objects, their size, the physics timestep, etc…
Yes, i understand, but why then if i set isTrigger to false it all collides perfectly(since i set collision detection to continuous)? I don’t get it really, the code is as simple is it can be