Using OnTriggerStay for Ground Detection
I understand that OnTriggerStay is called every FixedUpdate cycle. My concern is performance regarding the way I have utilized OnTriggerStay.
public bool onGround;
private bool groundCheck
void FixedUpdate () {
onGround = groundCheck;
groundCheck = false;
}
void OnTriggerStay (Collider collide) {
if (!collide.isTrigger) {
groundCheck = true;
}
}
My Game is a 3D game. I've setup the object with this script to have a trigger sphere poking out of the bottom of the actual collider. This script is specifically for detecting if the object is on the ground. The only variable being tracked by other scripts is the public "onGround" boolean.
I am anticipating that the floors in my game is made up of several parts. OnTriggerEnter and OnTriggerExit were not sufficient from my own experience.
I know this method works pretty well for my purposes, although I would like to know if I am making a bad practice of using functions which run on every fixed timestep. Like if there will be performance issue in a mobile project, or if there are better alternatives to ground detection.
Your answer
Follow this Question
Related Questions
2D Ground Check trigger messing up while overlapping multiple ground colliders 1 Answer
Omit Certain GameObjects From Loading At Runtime 0 Answers
Less code and avoiding unecessary If-statements 2 Answers
Cant walk through Trigger. 0 Answers
How do I make a platform fall after a player has left it? 2 Answers