i have a character which is moving in z direction with constant velocity.
lots of obstacle objects are occupied infront of character.
while user touches on obstacle objects infront of the character should get shooted.
camera is moving with character .
camera is child of character.
i used raycast to detect objects.
My problem is that sometimes it get destroys , and sometimes not.
Raycast not hit is my exact problem.
if(Input.GetMouseButtonDown(0)){
Ray ray = camera.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast (ray, out hit3, 1000.0f)){
Destroy(hit3.collider);
}
}
camera is not in (0, 0, 0) angle.
help with good solution.
Is it better to give raycast to character or camera?
Thanks in advance.