How to get bounds of a GameObject?

Hello,

I have a problem: I’m creating a small robot walking on the ground (now, for testing, I’m using a trivial “translate”, to “slide” it on the ground).
I do the following steps:

  1. I send Raycast on the ground (from the robot).
  2. Grab distance from ground. If the robot is too much near from the ground, then I set the robot Y-axis to:
hit.point.y + myMesh.bounds.center.y

“hit” is RaycastHit instanced object;
The problem is I cannot get “myMesh” (Mesh instance of my Mesh). My GameObject contains the mesh “g0”, and I tried as follows:

GetComponent(MeshFilter).mesh;

But I get the error:

(Filename: Assets/BOT_HERCULES/jsMove.js Line: 113)

Can you tell me how can I get a reference to the Mesh where the scripting is running into, so I could get its “bounds”?

Thank you for your help!

GetComponent returns a Component, .mesh is not a property of a Component, so you must cast the type appropriately.

(GetComponent(MeshFilter) as MeshFilter).mesh;

–Eric

Thank you! It works perfectly.
One question more: pplease can you explain me what is “MeshFilter”, since the manual is not so light?
I only understood it is related to Asset (mesh template).

THank you! :smile: