What determines a game object origin? (And how that affects ray casting)

This seems like a simple thing, but I am having a lot of trouble trying to find an answer in search. I just want to know what determines where a game object origin is (the transform position) and what sort of a typical convention would be for what I am trying to do (cast rays).

Use case: I create a 3D model in Blender and import it into Unity. For example, say a player or NPC character model. I add a Character Controller which has a Collider. I adjust the Collider to fit the model. I then want to do a RayCast from the model for some reason. When I do this, for convenience, I use the gameObject.transform.position. But that position is at the bottom of the model, and thus near the bottom of the collider. But when I’m raycasting, I will often want to do it from near the middle of the collider on the y axis (3D).

This creates a few questions.

If I want to ray cast from the center of the collider, I could just always adjust the start point for the ray cast. But is that proper convention? It doesn’t feel like it.

Is the game object origin in the wrong place? In other words, is this a symptom that my Blender model is not right?

Thanks for any insights.

Yes. Just raycast from where you need to raycast to come from. You can use an empty child game object to do this easily, and just reference its transform component via the inspector.

A 3d object’s origin should be used for editing convenience. Usually to snap things to the ground, or for snapping together modular pieces. I wouldn’t be thinking about raycasts or similar when deciding where that should be.

1 Like

Thank you. Also, I was taking a closer look at the API for Collider and I think I can use the Collider.bounds as an easy way to get different points on the collider. It has a center and an extents that I can utilize. In some cases, I want to cast rays from the edge of the collider. So I can use the center and then adjust with the extents if needed. This should work well as most of the time I only want to cast rays from game objects that have colliders.

1 Like