The problem i have is the AI should look at the player then when it hits a object with the tag Prop stop looking at the player and rotate then wait and look at the player again. This is my first attamp at AI and Raycasting so i am in a bit over my head i understand the logic of it but cant seem to get it coded correctly. I hope someone can help with this and if you do thanks ![]()
here is the code
var target : Transform;
var robotController : CharacterController;
var speed : float = 20.5;
var backwardsSpeed : float =-20.5;
var rayLength : float;
var lookAtPlayerTime : float;
function Start()
{
target = GameObject.Find("MadDoc").GetComponent(Transform);
robotController = GetComponent("CharacterController");
}
function Update()
{
var dir = transform.TransformDirection(Vector3.forward);
var dirleft = transform.TransformDirection(Vector3.left);
var dirright = transform.TransformDirection(Vector3.right);
var hit : RaycastHit;
Debug.DrawRay(transform.position, dir * rayLength, Color.black);
Debug.DrawRay(transform.position, dirleft * rayLength, Color.black);
Debug.DrawRay(transform.position, dirleft * rayLength, Color.black);
if(!Physics.Raycast(transform.position, dir, hit, rayLength))
{
if(hit.collider.gameObject.tag == "Prop")
{
transform.Rotate(0,30 * Time.deltaTime,0);
var forward1 : Vector3 = transform.TransformDirection(Vector3.forward);
var curSpeed1 : float = speed * Time.deltaTime;
robotController.SimpleMove(forward1 * curSpeed1);
}
}
else
{
var forward : Vector3 = transform.TransformDirection(Vector3.forward);
var curSpeed : float = speed * Time.deltaTime;
robotController.SimpleMove(forward * curSpeed);
LookAtPlayer();
}
}
function LookAtPlayer()
{
yield WaitForSeconds(lookAtPlayerTime);
transform.LookAt(target);
}
Please someone help!
β john-essyWhat is it doing now? What should it be doing? I'm not quite sure what parts of this script you are having problems with.
β syclamothBasically i want him to look at me until he hits something. Then stop looking at me and rotate and find his way round things to get to me. If that makes any sense
β john-essyBetter explanation. He should look at me until he hits something called Prop then if he does stop looking at me Rotate until he no longer hits anything and then smoothly look at me. Again if his raycast hits something then stop look at me then rotate. This is all i need him to do and he does but it is the look at player i need a way to smoothly look at me instead of just instantly turning and looking my way.
β john-essyAnyone? .
β john-essy