- Home /
Raycast Terrain And get the collider position for crosshair
I have one gun and move by mouse using MouseLook comes from Unity. And there is Terrain on my scense and one static camera, I have one ray from firePosition and after debug, the hit point is always in (0,0,0), but what I want is the explosion position of my projectile bullet for my crosshair.
Answer by luozitian · Feb 11, 2012 at 03:16 PM
finally I find the solution by LineCast and Use 3D object for my cursor. Post here for share. void CursorUpdate() { cursorTarget = cursorPoint.position + cursorPoint.TransformDirection(Vector3.forward * 5000f); if(Physics.Linecast(cursorPoint.position,cursorTarget,out cursorHit,~markLayer)) { if(cursorHit.collider.name == "Terrain") { cursor.transform.position = cursorHit.point; }
}
else
{
cursor.transform.position = cursorPoint.position + cursorPoint.TransformDirection(Vector3.forward * 200f);
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613063938im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Crosshair disappears? 2 Answers
first person crosshair 3 Answers
crosshair pointer 1 Answer
Make crosshairs disappear while aiming 0 Answers
Snapping Issue 2 Answers