- Home /
How can I get my script to recognise when a collider exits while the box collider of the trigger object is disabled?
My game has buttons which can be activated by placing cubes on top of them.
This works by using a trigger collider on top of the button. Ontriggerstay recognises that a cube is on top of the button Then Ontriggerexit recognises when the box is no longer on top of the button
My script that allows players to pick up and move boxes.
This script disables the box collider of the movable box when you pick it up to prevent the box from colliding with objects in the scene as you move the box around. Without this line, the box spins around and picks up momentum.
The issue I'm having is that when the box collider is disabled, the ontriggerexit doesn't trigger if the player moves the box off of the button by picking it up.
I either need:
1) A way to recognise when the the box leaves the trigger collider of the button while it has no box collider currently enabled.
OR
2) A alternative method to stop the carried box from spinning and picking up momentum without disabling the box collider.
Thanks.
Answer by ArtyD2 · Nov 29, 2021 at 02:31 PM
Hi,
I believe Rigidbody.isKinematic might help you achieve option 2 in fact the example given in the documentation seems to be exactly what you're after. https://docs.unity3d.com/ScriptReference/Rigidbody-isKinematic.html
Your answer
Follow this Question
Related Questions
MonoBehaviour.OnTriggerX vs Collider.OnTriggerX 1 Answer
How to use OnTriggerEnter with multiple triggered objects? 1 Answer
OnTriggerExit is not calling 2 Answers
Audio not playing after OnTriggerStay is applied to the scripts (Driving Simulator Project) 0 Answers
Can I access a script OnTrigger WITHOUT using getcomponent? 1 Answer