would collide with anything between the start point and the end point of the ray…
But what it’s doing (seemingly) is just colliding with the thing at the end of the ray regardless of whats in the way.
The image bellow shows the Debug.DrawLine of successful collisions going through walls (orange and grey blocks) and hitting the nodes (red spheres) that it was aiming for… (the image is busy and shows some pathing information as well so i’ve highlighted the errors in question)
I though these collision checks against the nodes would fail if it hit a wall.
Using a Linecast is simpler if you already know the start and end points. Anyway, if an object doesn’t have a collider, it won’t block a raycast. Also if it’s on the IgnoreRaycast layer. Other than that I don’t know what’s missing.
This time with a totally fresh project; just to make sure there was no screwy code messing things up…
This time I set up a plane with 2 walls (wall 1 and wall 2) and 2 cubes (start and goal)
Then I line cast between start and goal and got some really messed up results.
With wall 1 2 between start and goal… the line went through wall 1 and hit wall 2 (i did print(hit.collider.name) output to the console to verify) as seen here:
With no walls between start and goal… the line went from start and hit start like so:
I can understand the line going from starts centre hitting start as it passes out of it’s collider… but why didn’t it do this the first time and why did it also go through wall 1 and not wall2 ?
Do i need to reinstall Unity or am I doing things very wrong??
All the code from the project depicted:
using UnityEngine;
using System.Collections;
public class Game : MonoBehaviour {
public Transform start;
public Transform goal;
private Vector3 hitObj;
// Use this for initialization
void Start () {
RaycastHit hit;
if (Physics.Linecast (goal.position ,start.position,out hit)) {
print(hit.collider.name);
hitObj = hit.point;
}
}
// Update is called once per frame
void Update () {
Debug.DrawLine(start.position,hitObj,Color.green);
}
}
/EDIT: Just reinstalled (Mac OSX, latest indie version) … and no change
(Side note: I don’t quite understand the “should I reinstall Unity” questions I’ve been seeing lately…clearly that wouldn’t accomplish anything unless your hard drive is corrupting Unity itself, in which case it would almost certainly fail to work at all and you’d be having much worse problems with your system anyway…)