- Home /
Getting the gameobject(Plane in my case) from the collider he's got
Hi, after the program enters in the function "OnTriggerEnter", I want to gain access to the normal vector of the plane from the collider.
I tried the following:
Plane plano = (Plane)other.gameObject;
but Unity throws me the fallowing error:
Assets/Particle.cs(37,28): error CS0030: Cannot convert type System.Type' to
UnityEngine.Plane'
Any ideas?
Greetings
Answer by skovacs1 · Nov 30, 2010 at 03:34 PM
Think of the planes created in the editor as sort of like a prefab GameObject with a pre-defined mesh filter (and mesh) and mesh renderer to render that mesh filter and mesh collider attached. Like a prefab, they are not a type in and of themselves.
There is a Plane struct, but this is different than a plane GameObject and because this struct does not share the same properties or structure as a GameObject, you cannot convert from a GameObject to this struct. This struct is useful for invisible planes used in spatial calculations. Note how this struct and its constructor have no mention of or access to any sort of GameObject or Transform.
What you can do is use what is known about Plane GameObjects and GameObjects in general to find the information you want:
- Unless you've changed the mesh, the plane's normal will face along it's Transform's up vector. You can access this with
other.gameObject.transform.up;
- You can also access the mesh and get the normals from there. Because there is only one normal shared by all vertices on the standard plane, you can get it from something like:
PlaneMeshNormalsSample:
MeshFilter filter = other.gameObject.GetComponent(MeshFilter);
if(filter && filter.mesh.normals.Length > 0)
normal = filter.transform.TransformDirection(filter.mesh.normals[0]);
Can you give a few examples on how you would use the Plane struct? http://answers.unity3d.com/questions/32476/how-do-you-use-the-plane-struct
Your answer
![](https://koobas.hobune.stream/wayback/20220613085124im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
getting the normal vector from each side of a box collider 0 Answers
How do I stop my player from going through the platform? 1 Answer
physics.OverlapSphere colliders 1 Answer
What is Vector3.Exclude for? 2 Answers
Health Bar Alignment Issue 2 Answers