Here the raycast went out from camera. What i need is make it ignore hitting any object between camera and player. I got the distance between them but i don’t know how to make it ignore it ?
void FixedUpdate() {
Vector3 fwd = transform.TransformDirection(Vector3.forward);
// the distance between camera and player
float cam_player_ignore = Vector3.Distance(gameObject.transform.position, player.transform.position);
RaycastHit hit;
if (Physics.Raycast(transform.position, fwd, out hit,100)) {
print("Ray hit something !");
// here !!!
}
else {
print (" Nothing ");
}
Yes, the raycast went from the main camera and at end there is a crosshair image.
All thing is good until something between the camera and the player blocking the raycast. this thing could be enemy, wall, tree and whatever. To avoid this problem, i calculated the distance that i need the raycast to ignore it.
But i don’t know how to do it.