Enemy ignore walls in sight! Help!
Hello again, I made a vision script in raycast, but NOTHING works, I need a vision of SIMPLE RAYCAST but I did not find anything, all are very difficult tutorials for me, I look for a line in which the OBJECTIVE when entering a VISION CONE that DO NOT traverse the walls, that is, alter when the player is visible (raycast), the enemy is altered by the Booleans (I already do but the raycast receives nothing anywhere) I asked a question before about this but not It helped and I do not receive answers. This is my script:
using System.Collections;
public class EnemyRaycast : MonoBehaviour {
Ray ThugRay;
RaycastHit RayHit;
public float Distance;
public float DetectedDistance;
public bool Detected = false;
public Transform Target;
private int delayCount = 0;
private int maxDelay = 10;
public bool wasLastVisible = false;
void Start ()
{
}
void Update(bool IsPlayerVisible) {
delayCount++;
if (delayCount == maxDelay) {
delayCount = 0;
Vector3 dir = Target.position - transform.position;
RaycastHit hit;
if (Physics.Raycast(transform.position, transform.forward, out hit)) {
if (hit.transform.tag.Equals("Player"))
wasLastVisible = true;
else{
wasLastVisible = false;
}
}
}
}
}
Can you put a Debug.Log just after the Physics.Raycast? Just for making sure if its not colliding to any other object copy this line between both ifs
Debug.Log(hit.collider.gameObject.name);
and tell us whats logging, also try this line next to the debu.log so you now where the ray is going
Debug.DrawRay(transform.position, transform.forward, Color.green);
I did it but it does not mark anything to me, since recently it gives me an error of the Void Update (bool isplayervisible), it was Boolean. the drawray simply do not working. Do you know how to do a simple range of vision? Thank you
void Boolean (bool IsPlayerVisible) {
delayCount++;
if (delayCount == maxDelay) {
delayCount = 0;
Vector3 dir = Target.position - transform.position;
RaycastHit hit;
if (Physics.Raycast(transform.position, transform.forward, out hit)) {
Debug.Log(hit.collider.gameObject.name);
if (hit.transform.tag.Equals("Player"))
wasLastVisible = true;
else{
wasLastVisible = false;
}
}
}
}
}
Your answer
Follow this Question
Related Questions
Having trouble with player health 0 Answers
How to activate "OnTriggerEnter" when Player ray hits an object collider? 1 Answer
Graphic Raycaster doesnt take into account fill image parameter. 0 Answers
Raycast is not hitting collider 2 Answers
Is there a way for creating composite raycast collisions ? 0 Answers