How can I raycast a flat mesh?
Ok. So I have a brand-new mesh generation system for a sandbox game. I started writing it so that it creates a mesh instead of individual sprites. I add a collider to it afterwards. However, I am having trouble wrapping my head around how to raycast it from the player to collide. I wrote a very nice player controller that worked fine with BoxCollider2D's when the game was written in 2D, but after switching to mesh generation for performance improvement all my work seems to be redundant. I use raycasting because I find it much more reliable than the Unity2D physics system. The problem (at least I think) is using Physics2D.Raycast and RaycastHit2D. However, I tried just raycast and that didn't work either. It is because I'm raycasting from a direction in which the mesh has no thickness. Hope this can all be settled, thanks in advance! :)
Refine the problem more? I can't tell what it is, but seems like there might be a different way to think of it?
You raycast a single line (a ray) onto a collider. Can circleCast a fat line, or BoxCast. You actually want a "meshcast"? What are you casting it onto? You really have two different complex meshes which need to be checked for intersection?
Nonono, I want to raycast and hit a mesh that has no thickness in the direction im hitting. I have a sidescroller sandbox and it has no depth. I want to raycast from the player but I'm sinking through the ground.
Answer by mahdiii · Mar 05, 2016 at 01:37 AM
if you use mesh you must use Physics.Raycast and define Ray ray. Physics2D.Raycast belongs to sprites.