workaround found
Problen with collision events when changing rigidbody to iskinematic
Hi,
i have a problem where i get unexpected calls to OnCollisionExit when my player "enters" a vehicle.
My whole scene and all objects within it are inside a giant sphere collider and i have a script that deletes all objects leaving it like this:
void OnTriggerExit (Collider other)
{
Destroy(other.gameObject);
}
This is supposed to delete objects falling into infinite space.
So far, so good.
Now, i wanted to attach the player to a vehicle, using a "VehicleControls" script, that basically does the following:
...
player.transform.parent = playerPos;
// playerPos is a GO on the vehicle where the player should be placed
player.transform.localPosition = Vector3.zero;
player.transform.rotation = playerPos.rotation;
...
Rigidbody rgbPlayer = player.GetComponent<Rigidbody>();
rgbPlayer.velocity = Vector3.zero;
rgbPlayer.isKinematic = true;
...
Upon setting isKinematic, OnTriggerExit on the delete script is called and removes the whole player object, which isn't supposed to ever happen, and i get nullpointers in all kinds of other scripts.
A debug log shows that at the time of the event, both the vehicle an player are clearly inside the collision sphere.
What the hell is happening here?!
Well, i made a little workaround and "inverted" the remover collision by using a handful of box colliders as world bounds.
This seems to do the trick...
Follow this Question
Related Questions
Sphere bouncing back on edges of aligned objects 0 Answers
Restrict held object movement 0 Answers
Position and collider seem to incorrectly shift when moving object 0 Answers
2.5D Platformer - Platorm Box Colliders Randomly Stop Colliding 0 Answers
Freeze rotation of just the box collider component 0 Answers