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
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]);