Where's an objects base

Hi all,

I’ve kind of asked this question before but I think I may have worded it badly :slight_smile:
I wish to know the point at an objects base. By ‘base’ I mean the point at which it would stand on; I guess it’s lowest point.
Doing a raycast to find the ‘floor’ is fine; but that goes from the centre of the object.
I’ve looked at extents/size etc. but can’t find a reliable method. Essentially I am after the lowest point of a collider irrespective of whether it’s a cube/sphere/capsule etc.
The reason for this is that I need to know when an object is on the ‘floor’ . The ‘floor’ being a tagged object with box collider.

Cheers

You could try creating an empty Game Object and positioning it at the bottom of your object and raycasting for that. But if you want to know if an object is on the floor, couldn't you just use OnCollisionEnter()???:

function OnCollisionEnter(hit: Collision){
    if(hit.gameObject.tag == "floor"){ //check if colliding with your floor
        //If true, perform code in here
    }
}

Just attach that to your object, and it will be able to check if it's hitting the floor!!!!!!!!!!!!!

Hope this helps!!!! Comment back if you need more help! :D

-Grady

Markh, I think I might have the answer you want. It is very simple and a common thing to do.

I guess it’s quite common to add “pointless” “position markers” to models in games. You might use them for algorithms, for physics, or for some other reason.

For example, I was looking at a rocket ship model. It could be hit by missiles on any part of the body. If it was hit “near a certain area” then something happened. How to test that it is “near a certain area”?

I trivially added a new empty object to the model. In other words, it’s just a transform that sits there in the model. I put it near the area of interest. On a collision, I very simply look at the distance from the collision to that “special marker”. the good thing is the designers or whoever can just move that marker around to achieve a result they like in gameplay.

Another example is very often you might “mark” the centre of gravity of a model, and use that for some calculations or other. Again you just use a plain transform that sits there in the model.

(To be clear for new users, just make a new empty object in the scene, and simply drag it inside the folder being the vehicle/thing in question. It will now be part of and stay with the object, no matter what happens to the object, if it tumbles, etc.)

So in this case Markh, for a cube. Just add 8 markers on all the corners.

To find the “bottom” of the cube collider?

Just look at the Y values of each, the lowest one is the absolute lowest point of the whole cube. That’s it.

(Alternately obviously if you know it won’t tumble over, you could just use the four bottom points, or whatever works in your situation.)

By the way: you also mention a “sphere”. I shouldn’t have to tell you that the lowest point on a sphere is: the center minus the radius :slight_smile: For a capsule collider, it is the lower of the two end-centers minus the end-radius.

(It goes without saying that with a cube/rectangular-cube you could also just calculate it using the current tilt angle and the lengths - but I think it’s more in the spirit of Unity to just mark the corners like I describe, and the lowest one at any moment, is your lowest point. NOTE THAT you also usefully, for free, get a transform you can “lookAt”, use to draw rays, etc etc.)

The good news is you can even generalise this to some mesh colliders, if you think carefully about the points it can possibly rest on.

Hope it helps!