Hi everyone, I’m trying to figure out how you would detect the edge of an object in a script.The edge itself isn’t a gameobject so how would you go about detecting it? Any help would be appreciated.
Add an other thinn and long collider and parent it to the object, or does anyone have a better idea ![]()
What kind of ‘edge’ are you talking about. The edge of a collider…or maybe a specific vertice from a mesh?
You can try Renderer.Bounds.
The edge of a collider. Like the cube gameobject.How would you detect those edges?
I’ve heard that you can use raycasting to detect edges.But I don’t understand how that would work.Has anyone here used raycasting to detect edges?
You have to provide more detail. The terms “detect” and “edge” both have several technical meanings here. “Edge detection”, as in the Sobel filter, is probably not what you mean. So, what exactly do you mean?
By “edge”, do you mean the 2D sillhouette of the object as seen from any perspective, or the actual edges between verts, or the surface of the object itself in 3D? Or something else?
By “detect”, do you mean show graphically, search for, raycast against, or something else?
Please provide a less ambiguous explanation of the problem you are trying to solve.
Cheers
Collider.Raycast
The hitInfo returned from this is very detailed, you can get just about everything you need from it. Very helpful for determining things like the specific normal angle of where the ray hits. You can also get details like points on a texture.
More info about what is returned here:
I am pretty new to scripting, but I am working on a game where I need to be able to detect if I am within a certain distance away from the edge of say, a cube. I then need to transform my player to that edge, and then carry on from there. Any ideas? I thought about using a sphere check to see if an edge was near, but I still don’t know how to go about it.