Hi guys I am using the below script to make it so that the animal runs away but the problem is that it keeps on jumping away which I don’t want so can someone tell me how to make player.GetTransform use only X and Z no Y axis, also the character runs super slow no matter what I change t he run speed to.
using UnityEngine;
using System.Collections;
public class AnimalAI : MonoBehaviour {
PlayerMove player;
Transform thisTransform;
public float minDistance = 40;
public float runSpeed = 60;
void Awake() {
thisTransform = transform;
thisTransform.position = new Vector3(7, 0, 9);
}
void Start() {
player = GameObject.Find("Jim").GetComponent<PlayerMove>();
}
void Update() {
if(Vector3.Distance(player.GetTransform().position, thisTransform.position) < minDistance) {
Vector3 direction = thisTransform.position - player.GetTransform ().position;
direction.Normalize();
thisTransform.position = Vector3.MoveTowards(thisTransform.position, direction * minDistance, Time.deltaTime * runSpeed);
}
}
}