I am creating a simple bike AI. I want my AI bike to move towards player. If its ahead then slowdown and if its behind then speed up.
Heres what i did so far.
public class BikeAI : MonoBehaviour {
Rigidbody rb;
public GameObject playerbike;
Vector3 newvelocity;
// Use this for initialization
void Start() {
rb = GetComponent<Rigidbody>();
playerbike = GameObject.FindGameObjectWithTag("Player");
rb.velocity = new Vector3(10, 0, 0);
}
// Update is called once per frame
void Update() {
float zz = playerbike.transform.position.z- transform.position.z;
float xx = playerbike.transform.position.x - transform.position.x;
Debug.Log(playerbike.transform.position.x);
Debug.Log(xx);
rb.velocity = new Vector3(xx*20,0,zz);
}
}
Now problem is bike forward movement seems to be extremely jerky. Anyway to fix this