erm, ok, here are a couple of easy ai thoughts. U can take them as u need them, or just not use them, ur choice.
First, convert the targets position to a local position, and make sure Y is zero.
Next, get the angle between the target and the object. u can use Vector3.angle to get it.
Next, u need to know if that angle is left or right of the vehicle, Left is a negative angle, right is positive ( or the other way around) Use the target.x. If it is positive, it is on the right, negative, left.
Next, use the target.z to figure out if it is in front or back. positive, front, negative back.
Now, we need to convert this to steer and gas inputs, just like a player. To do this, all we have to do is hold a max steer angle, and divide our angle by that, then clamp it to -1 and 1. Gas is either -1 or 1 and that is it.
lastly, u need to use the gas as a measure. If ur backing up, reverse the steering.
Alternatively, u can use Vector3.Dot to get the gas info. If it is greater or less than an amount, u can change ur forward and back directions at different angles.
Simple code
using UnityEngine;
using System.Collections;
public class test : MonoBehaviour {
public float maxSteer = 40;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
transform.LookAt(transform.position + Camera.main.transform.up, -Camera.main.transform.forward);
Plane plane = new Plane(Camera.main.transform.forward, transform.position);
Ray ray = Camera.main.camera.ScreenPointToRay(Input.mousePosition);
float dist;
if(plane.Raycast(ray, out dist)){
Vector3 localPoint = transform.InverseTransformPoint(ray.GetPoint(dist));
localPoint.y = 0;
float steer = Vector3.Angle(localPoint , transform.forward);
steer = (localPoint.x < 0 ? -steer : steer) / maxSteer;
steer = Mathf.Clamp (steer, -1, 1);
float gas = localPoint.z < 0 ? -1 : 1;
// alternative to local.z
gas = Vector3.Dot(Vector3.forward, localPoint.normalized) > 0.2f ? 1 : -1;
steer = gas == 1 ? steer : -steer;
Debug.Log ( "Steer: " + steer + ", " + "Gas: " + gas );
//Debug.Log( steer);
}
}
}