Raycast not detecting hit with mesh
I am making a third person camera system following spaceship flying within tunnels. I need to make sure the camera remains within the confines of the tunnel. I'm trying to use the raycast to detect if the tunnel mesh is between the camera and the spaceship object, but I'm not getting a hit.
I'm using Debug.Drawline() to debug, and here is the relevant portion of the code.
RaycastHit hit;
Debug.DrawLine(target.position, target.position - offset, Color.yellow);
if (Physics.Linecast(target.position - offset, target.position, out hit))
{
Debug.Log("point : " + hit.point + "name :" + hit.collider.gameObject.name);
if (hit.collider.gameObject.tag == "Environment")
{
newPosition = hit.point;
}
}
I have tried switching the start and end point arguments of the Linecast(), but that doesn't help. There is no layermask, and the mesh prot_track is in the Default layer.
I've attached a screenshot showing the problem.
No. I just tried it, and the mesh created as a result is not going to work - the convex mesh created is in no way representative of the mesh I want to detect collisions with. The image of the complete mesh is below. Is a convex mesh required?
Your answer
Follow this Question
Related Questions
Get Face/Triangle size in world space from RaycastHit 0 Answers
RayCast(Ray ray, out RaycastHit hitInfo, float maxDistance, int layerMask) question 0 Answers
Raycast shooting, child collider call and detection 0 Answers
Raycast not detecting a gameobject. 1 Answer
Does Unity support raycasting to meshcolliders from FBX files ? 0 Answers