I’ve struggled trying to make a simple car model chase a player and ram into him (Rigidbodies)
Any pointers on this?
I just want a simple car that does not fly off the ground when chasing the player, but simply drives towards the player at ground level and rams him without spazing out.
using UnityEngine;
using System.Collections;
public class aiDRIVE : MonoBehaviour {
public float movementSpeed;
public Transform player;
public Vector3 thePosition;
public float yvalue;
public float lockPos = 0;
public Transform target;
void Start () {
yvalue = 0.00f;
movementSpeed = 15.0f;
thePosition = player.position;
}
void Update () {
if (transform.position.y > 0) {
transform.position = new Vector3 (transform.position.x, 0, transform.position.z);
}
transform.rotation = Quaternion.Euler(lockPos, transform.rotation.eulerAngles.y, transform.rotation.eulerAngles.z);
Vector3 targetPostition = new Vector3(player.position.x, this.transform.position.y, player.position.z);
transform.position += transform.forward * Time.deltaTime * movementSpeed;
transform.LookAt (targetPostition);
}
}