- Home /
opposite of ontriggerstay
Is there an inverse to OnTriggerStay or work around? I am dealing with an object that is getting "teleported" back and forth / disabled, so OnTriggerEnter/OnTriggerExit don't work. I've tried looking around the internet and searching the unity answer forums but the only solution recommended to use enter/exit and it doesn't work for what I need.
Answer by ahstein · Jul 28, 2020 at 08:19 PM
It is hard to give suggestions when we don't know what you're actually trying to accomplish.
It is possible that Physics.OverlapBox (or OverlapSphere, OverlapCapsule, etc.) could accomplish what you want. If it returns null, that means there's no overlap. Raycasting could probably also accomplish something similar. CheckBox as well. https://docs.unity3d.com/ScriptReference/Physics.html
FYI, OnTriggerEnter/Exit doesn't require the object to cross the boundary of the collider. It just fires on the first frame that a collider is overlapping with the trigger.
These do seem like viable solutions. I tried to delete my question but It wasn't letting me. I am using an offline PC therefore can't copy and paste code easily so I tried to give the more important features. To give more detail, the player picks up an item (if the hand if over the item it is able to grab(ontriggerstay)). Once the object is grabbed, if it is released, returns to its original position. Currently, if you just close the hand again (without reaching for the item) it thinks the item never left your hand (OnTriggerExit never triggered) and places it back in your hand. The solution I came up with was crude (if you release, set the bool that you are in the trigger space to false). But I will try physics overlap as it is the more correct answer. Thank you.
Your answer
Follow this Question
Related Questions
Check how many objects are in a trigger? 1 Answer
Editor vs Build: OnTriggerStay & Physics Issues 0 Answers
Why is my 2D Collision Delaying or Missing? 0 Answers
Ask for trigger-collision inside Update() 1 Answer
flamethrower 2D not hitting sometimes 2 Answers