This question was
closed Feb 23, 2018 at 12:23 AM by
PaincideStudio for the following reason:
Update using only raycast is not good way I think. I should use raycasting with trigger.
Question by
PaincideStudio · Feb 22, 2018 at 10:59 PM ·
raycastraycastingelse
Raycasting else not working properly
Hi.
I'm having a issue about 'else' when using Raycasting.
What I want is if raycast is not hitting Player, it should always be false(doesn't matter if raycast hits nothing, wall, furniture).
I tested with debug.log and empty gameobject.
But it sometimes debug.log and most of the times, it doesn't debug.log anything.
Also the falsed emptygameobject should set to true when it is not looking at Player, but it never does..
Here is the script.
void Update()
{
RaycastHit see;
Vector3 rayDirection = Player.transform.position - sight.position;
if((Vector3.Angle(rayDirection, sight.forward)) <= fieldOfViewDegrees * 0.5f)
{
if (Physics.Raycast (sight.position, rayDirection, out see, 50.0f)) {
if (see.collider.Comparetag ("Player")) {
Debug.Log ("I see you");
Debug.DrawRay (sight.position, sight.forward, Color.red);
wandering = false;
manager.SetActive (false);
}
else
{
Debug.Log ("false");
wandering = true;
manager.SetActive (true);
}
}
else
{
Debug.Log ("more false");
wandering = true;
manager.SetActive (true);
}
}
Comment