Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

Enemy ai Ignore walls! help!

$
0
0
Hello, it turns out that I have created an AI script that works like this: the enemy has a distance of detection of the player, when the player enters that area, the enemy looks at it until the player moves away, but it turns out that the enemy detects my player through the walls or colliders (I mean, if I hide behind a wall he detects me the same), does anyone know anything? Thank you! #pragma strict var Target : Transform; var Animador : Animator; var Distance : float = 30; var rotationDamping : float = 2; function Start () { Animador.SetBool("Aiming", false); } function Update() { var distance = Vector3.Distance(Target.position, transform.position); if(distance <= Distance) { LookAtTarget(); Animador.SetBool("Aiming", true); } if(distance > Distance) { Animador.SetBool("Aiming", false); } } function LookAtTarget() { var dir = Target.position - transform.position; dir.y = 0; var rotation = Quaternion.LookRotation(dir); transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * rotationDamping); }

Viewing all articles
Browse latest Browse all 1488

Trending Articles