|
I have a ball that has forces applied to it when i press the corresponding arrow keys. I didn't realize before that even if the ball is in the air, the arrow keys will still apply forces to the ball and it will be able to move in the air. I'm thinking of fixing it by putting the movement code with the forces inside the OnCollisionStay check. That way the ball will only have forces applied to it when it's touching the floor(I assume I can put some kind of ignore tags on walls, etc later). Is this a proper and efficient way of solving this problem, or is there a simpler more elegant solution, perhaps a unity function i'm not aware of?
(comments are locked)
|

To be more clear, what i mean is: OnCollisionStay ill set a toggle variable such as moveallow = 1; Then in the FixedUpdate() function ill have an if statement check the moveallow variable, and the movement addforce code will be inside.
And im just wondering if thats an efficient way of doing it, or is there some function im not aware of that's simpler and more elegant.
And OnCollisionExit i can set moveallow = 0 right???
OH OH maybe i can use OnCollisionEnter()to make moveallow = 1 and just use a floor tag to make sure it's touching the floor! Then OnCollisionExit() i can see if it's exiting the floor and then set moveallow = 0! This means the Collision check only happens 2 times and the entire time the object is on the floor, no collision calculations have to be done!!!
This sounds pretty elegant to me. Any opinions?
Looks like you've thought that one through yourself :)
Sounds like it would work to me....
but how would YOU do it lol?