Hey!
I have been working on an basic AI for a week now and I am stuck with trying to make the enemy follow the player.
Here is the code that isn’t working:
private var playerPos;
private var objectFollow;
function Start(){
objectFollow = GameObject.FindWithTag("Player");
}
function Update(){
if(GUITest.taBortOk == true && GUITest.pausKnapp == false){
if(continueChase == true){
Vector3 playerPos = new Vector3(objectFollow.position.x, this.transform.position.y, objectFollow.position.z);
this.transform.LookAt(playerPos);
}
}
I get an expected semicolon message at: Vector3 playerPos = new Vector3(objectFollow.position.x, this.transform.position.y, objectFollow.position.z);
I am trying to limit the AI so it doesn’t follow me up in the air if I for example jump, therefor using the this.transform.position.y
You don’t have to worry about the if-statements, they are working fully, the problem is just the playerPos.
Any help would be much appreciated!!
private var objectFollow;
private var continueChase : boolean = false;
private var playerPos : Vector3;
function Start(){
objectFollow = GameObject.FindWithTag("Player");
}
function Update(){
if(GUITest.taBortOk == true && GUITest.pausKnapp == false){
if(continueChase == true){
playerPos = Vector3(objectFollow.transform.position.x, this.transform.position.y, objectFollow.transform.position.z);
this.transform.LookAt(playerPos);
transform.Translate(Vector3(0,0,Time.deltaTime * 8));
}
}
//follow();
if(GUITest.taBortOk == true && GUITest.pausKnapp == false){
if(continueChase == false){
transform.Translate(Vector3(0, 0, Time.deltaTime * 3));
transform.Rotate(Vector3(0,Time.deltaTime * 3));
}
}
var hitRay : RaycastHit;
Debug.DrawRay(transform.position,transform.forward * 500, Color.green);
Debug.DrawRay(transform.position,transform.right * 500, Color.red);
if(GUITest.taBortOk == true && GUITest.pausKnapp == false){
if(Physics.Raycast(transform.position, transform.forward,hitRay, 10)){
var objectHit : GameObject = hitRay.collider.gameObject;
if(objectHit.tag == "Player"){
continueChase = true;
}
}
}
if(GUITest.taBortOk == true && GUITest.pausKnapp == false){
if(Physics.Raycast(transform.position,transform.forward, hitRay, 5)){
if(objectHit.tag == "TerrainCollision" || objectHit.tag == "Target" || objectHit.tag == "Moveable"
|| objectHit.tag == "Wall"){
continueChase = false;
transform.Rotate(0,Time.deltaTime * 10 + 25,0);
}
else{
}
}
}
}