- Home /
Alternative to OnTriggerStay2D
I am coding some water and need a method to check if entities are in water or not. I am not even going try using OnTriggerStay2D if I want a playable game (which I do).
I am considering using a empty gameobject parented to entities with a collider only sensitive to water and using onTriggerEnter and onTriggerExit but there probably are better methods.
I am not even going try using OnTriggerStay2D if I want a playable game
Why is that? The physics engine runs regardless of whether you use OnTriggerStay2D
or not.
Yes, you can use OnTriggerEnter2D + OnTriggerExit2D + boolean + Update, but I don't feel it will be better for performances (Update can run more frequently than the Physics Engine)
I haven't really heard many good things about onTriggerStay and performance. I guess it updates values too often?
Also, there is no way I am using things like this in $$anonymous$$onobehaviour.Update.
Wait, what does OnTriggerEnter/Exit have to do with Update?
Answer by logicandchaos · Jan 10, 2021 at 02:37 PM
onTriggerEnter and onTriggerExit seems to be the right way to do it, but I found it's not reliable, sometimes the one won't be called leading to buggy behaviour, there is collider.IsTouching(otherCollider); and you could do something like: bool isInWater; isInWater=collider.IsTouching(otherCollider); putting it in update may cause performance issues, you should probably call it when player is moving vertically. You could also use OverlapCircle()
I never even thought about the collider component methods :P. Overlap methods it is. :)
Your answer
Follow this Question
Related Questions
Having trouble with my water texture 0 Answers
AQUA Water null problem 0 Answers
Hiding part of mesh 0 Answers
Better particle waterspray? 0 Answers
Physics changes in 3.3 0 Answers