Hi there,
I’ve got a raycast to check whether a target can be fired at (as in, if he;s not behind a wall, etc)
here’s the code-
Vector3 fwd = (target.transform.position - transform.position).normalized;
RaycastHit hit;
Debug.DrawRay(transform.position, fwd * 10, Color.blue);
if (Physics.Raycast(transform.position, fwd, out hit, 20)) {
Debug.Log(hit.collider.gameObject.name);
if(hit.collider.gameObject.tag == "enemy") {
controlthing.GetComponent<lightning>().shouldgo = true;
}
else if(hit.collider.gameObject.tag != "enemy") {
controlthing.GetComponent<lightning>().shouldgo = false;
}
}
Can anyone see what i’m doing wrong here?