Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Accurate raycasting a single object that is very curved without a portion.

Discussion in 'Scripting' started by aeo34, Jul 15, 2019.

  1. aeo34


    May 6, 2019
    Hello, my problem is an original one that I haven't found an easy solution to. I am trying to spherecast/raycast to the a point on the object. But the gray part, not the lines or another thing just to the gray portion of the object. Raycasting and SphereCasting ask for colliders but when using a mesh collider, raycasting only works with convex turned on (for mesh colliders) and the convex option show are the green-ish lines. This leaves a major room for error in the object and where the spherecast/raycast is targetting. Is there a way to keep the object true to it's form and accurately get the Vector3 of object? Any suggestions would be helpful or is there a fundamental way that I can change what I am doing to fix this issue?

    Methods I used:
    NonConvexMeshCollider asset --> for some reason doesn't take over 100 boxes and tries to micmic a previous feature of the mesh collider known as concave by creating a ton of box colliders doesn't allow me to set a parent of transform. When it does it bugs out on planes or only makes them in a certain part.

    Box Collider --> Method sort of works but tedious and doesn't accurately replicate the object.Furthermore, scalability is non-existent given that one object can take anywhere from 3 to 250 box colliders and if you had 60 object, this is virtually an adderall/coffee filled focus-task, I implemented this by creating a child gameobject and adding a ton of box colliders, I started with capsule and sphere colliders but it adds a level of error given that in the y- dimension.
    --> doesn't allow you to rotate, which is the reason it comes up to 250 box colliders. Furthermore adds another complexity given that that for sphercasting you may have more than one of this box collider in the given radius or a raycastall length. Like raycasting/spherecasting will have to determine the closest object in the child, not hard but there has to be an easier way in all of this

    Turning off Convex (mesh collider) - Raycast/SphereCast does not pick up object, raycast back to the origin source of the raycast/spherecast

    Turning on isTrigger with Convex (Convex is a parent option of isTrigger (mesh collider)) --> follows the green line, effectively the same as simply putting Convex

    Just turning on Convex (mesh collider) --> follows the line green line as opposed to where the object is (it finds the shortest distance given 250 triangles or less in an object

    Please any amount of advice would be great!

    Attached Files: