x


Check if collider touching anything

I have a collider that is subject to 2 control methods. It is a wheel. When on the ground, I propel it, naturally, by adding torque, but I want to be able to move it in midair. I figured I would just add Forces, but I don't want the forces to be applied when the wheel it just sitting. So, in short, how to I check if the collider is on the ground or not?

Note: I am NOT using a character controller, as I need to be affected by physics. I know it is easy that way, but a ChracterController is not an option.

more ▼

asked Jun 27 '11 at 05:22 PM

qwertyp gravatar image

qwertyp
164 14 15 21

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Well, if it's a wheel, it's probably worth your time checking out the Wheel Collider docs.

To answer your question, you would use OnCollisionStay with an if statement checking that the tag of the collider it's hitting is ground or some other appropriate tag you choose. Then you just make sure you tag anything you want as ground and then put your appropriate torque code in that if statement.

OnCollisionStay(col:Collision){
    if (col.gameObject.tag == "ground")
        //apply torque
more ▼

answered Jun 27 '11 at 05:41 PM

Chris D gravatar image

Chris D
2.5k 5 7 25

That did it. Thanks! Though right after it turned out I could just add force and torque at the same time and it didn't mess things up, so the whole question was unnecessary. Ah well. Thanks though!

Jun 27 '11 at 07:31 PM qwertyp
(comments are locked)
10|3000 characters needed characters left
Your answer
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:

x1684
x577
x40

asked: Jun 27 '11 at 05:22 PM

Seen: 2878 times

Last Updated: Jun 27 '11 at 07:31 PM