- Home /
Linecast blocked by colliders not actually in the way?
I'm having trouble with a Linecast that goes from a "sun" object to all the cubes on a board. The Linecast appears to be getting interrupted by cubes that are not in the way of what should be a straight line from the center of one transform.position to another.
Here's an example of what I'm talking about:
In the above pic, if I remove the cube I've circled, the Linecast hits the target I've pointed to. All of these objects are on the same Z, so that's not the problem.
Here's an example of their Vector3s here:
linecast origin: 0.5f, 0.1f, 0f
target: 0.4f, -0.6f, 0f
blocking: 0.3f, 0.1f, 0f
I'm really baffled. The blocker is actually further to the left than the target. What is happening to the Linecast here?
Just for completion's sake, here's the snippet of relevant code:
foreach (SideDigScript d in allCubes) { Vector3 blockPos = d.transform.position; if (Physics.Linecast (theSun.position, blockPos, out hitInfo)) { if (hitInfo.collider.gameObject.GetComponent<SideDigScript>() == d) {
// bla blah
try to use Debug.DrawRay(theSun.position, blockPos) to see whats actually going on.
Raycast is based on the colliders, not the physical object. Turn on Gizmos and click on your blocks in the hierarchy to verify the are the correct size. And follow @cmo's suggestion of doing a Debug.DrawRay() to verify the path of the Raycast.
Thanks guys -- the colliders are correct size. I've also got gizmos on and have checked placement.
Debug.DrawLine is new to me, much appreciated! I've got it on and can see the problem now. However.. I'm just as confused. It looks like one of the lines stops before it reaches the block.
So.. Debug is helping show me that something is wrong, but not what it might be. This project doesn't have a lot of code yet, and I've looked over what's there to try to make sure rogue particles or objects couldn't possibly be showing up for a split second. Any ideas?
Oops, and I figured it out a second after posting. I'm destroying the old block through code, and the DrawLine is being called first, so it hits the collider while it's still there. Thanks for the pointer to Debug!
Your answer
Follow this Question
Related Questions
Help with Raycast C# 0 Answers
RayCast or LineCast? 1 Answer
Raycasting along line renderer width 1 Answer
Multiple linecasts question 1 Answer
Ricochet Problem of projectile bullets 0 Answers