x


How to test colliders C#

I have a rotating ball on a plane that the player rotates. I need to test/check to see that the ball is still on the plane (that way, if not, I can stop the game).
I've tried using raycast with no success, and that seems to be because both objects have the ability to rotate. Here's what I've used:

        Vector3 Up = transform.TransformDirection(Vector3.up);
        if (Physics.Raycast(transform.position, Up, 10))
            print("There is something in front of the object!");

It seems I need to not only check if the two objects are touching, but I need to check a little radius around the ball since it can end up slightly off the plane if you tilt the plane to it's extremes. I thought raycast would be perfect here, but no avail. Thanks for the help.

more ▼

asked Apr 16 '12 at 10:01 PM

mnm2317 gravatar image

mnm2317
24 8 16 17

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

1 answer: sort oldest
public void OnCollisionStay(Collider col)
    {
       if (col.gameObject.tag == "wall")
         Debug.Log("There is something in front of the object!");
    }

with that script attached to the plane and the sphere tagged as a wall or vice versa.

more ▼

answered Apr 16 '12 at 10:13 PM

DJSwiti gravatar image

DJSwiti
105 6 8 9

It's saying "OnCollisionStay" is a script error. Is it C#?

Apr 17 '12 at 07:46 PM mnm2317

Ok, "OnCollisionStay" gives me no errors (looks like your original answer said "Collider col" when it needed "Collision col", at least according to the link there.
Problem is I put that code in the 'plane' script (replaced "wall" with "ball") and I get no errors but I also get no debug message either.

Apr 19 '12 at 06:55 PM mnm2317

Yea sorry it was Collision and not Collider.. But it means that your objects aren't in collision.. Have you tried to move the cube while in collision with the plane ? Do you still have no Debug.Log ?

Apr 20 '12 at 05:01 PM DJSwiti

did you tag the object or name the object? Make sure you use the proper one.

Apr 20 '12 at 05:05 PM fafase
(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:

x4152
x1528
x281

asked: Apr 16 '12 at 10:01 PM

Seen: 1039 times

Last Updated: Apr 21 '12 at 07:14 PM