- Home /
The question is answered, right answer was accepted
Raycast isn't working on small distances
Hello,
I try to make a raycast to identify the tag of an object, but when the player (CharacterController) walk to close to it, it dosn't recognise the object.
var hit : RaycastHit;
var Reach : float = 5.0;
var RayHit : boolean;
function Update () {
var fwd = transform.TransformDirection (Vector3.forward);
Debug.DrawRay(transform.position, fwd * Reach, Color.red);
if (Physics.Raycast (transform.position, fwd, hit, Reach) && hit.transform.tag == "Fish") {
RayHit = true;
}
else
{
RayHit = false;
}
}
Have you checked that the starting position of the ray is not actually inside the colliding object?
The script is on the camera of the first person controller
to fix it you have to set a layer$$anonymous$$ask target for your Raycast. But i guess you already know.
Answer by robertbu · Jun 19, 2014 at 07:09 PM
If the FPS is inside the CharacterController at the point you are raycasting, then the Raycast will fail.
yes, it was this, it was first raycasting the player itself!
This fixed my issue. Thank you. Guys, make sure to put the Player Camera outside of the CharacterController component. I put it in front of the CharacterController and it totally works.
Follow this Question
Related Questions
Exclude tag from raycast 1 Answer
What is the best way to navigate through a grid based level using Raycasting ? 2 Answers
Change raycasting 1 Answer
Raycast on touch 3 Answers
gameObject tag 2 Answers