x


Ball colliding with floor as it's rolling

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?

more ▼

asked Jun 13 '12 at 09:21 PM

luniac gravatar image

luniac
37 6 16 23

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.

Jun 13 '12 at 09:38 PM luniac

And OnCollisionExit i can set moveallow = 0 right???

Jun 13 '12 at 09:39 PM luniac

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?

Jun 13 '12 at 09:41 PM luniac

Looks like you've thought that one through yourself :)

Sounds like it would work to me....

Jun 13 '12 at 10:05 PM whydoidoit

but how would YOU do it lol?

Jun 14 '12 at 01:49 AM luniac
(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2485
x244
x169
x39

asked: Jun 13 '12 at 09:21 PM

Seen: 427 times

Last Updated: Jun 19 '12 at 07:17 PM