Ok so I gave up the navmesh/agent way of doing AI for my vehicles. Its not going to work because of many reasons not just it being too stupid, so I am making my own. My game WIP: http://forum.unity3d.com/threads/200629-Omega-Void-WIP
What I need now is for my car to reorient itself left or right in the general direction of the target… Or turn around completely(but that is not needed yet).
I got it to stop and reverse so far but need it either to pick right or left depending on the direction of the target.
Here I am using 3 rays to detect whats in front and then stop. Shaped like spread out fork or three fingers pointing out at the front.
How would I make it choose to turn left(or right) and move forward until the rays are not hitting?
Code:
target = waypointHolder.transform;
Vector3 relativeWaypointPos = transform.InverseTransformPoint( new Vector3(wayPoints[currentWaypoint].position.x, transform.position.y,wayPoints[currentWaypoint].position.z));
// Vector3 targetDir = target.position - transform.position;
targetDistance = Vector3.Distance(transform.position, target.transform.position);
Vector3 chassisLook = chassis.TransformDirection(new Vector3(0, -navSeeDistance, 0));
Vector3 left = chassis.TransformDirection(new Vector3(-navSeeLeftDist, -19, 0));
Vector3 right = chassis.TransformDirection(new Vector3(navSeeRightDist, -19, 0));
RaycastHit chit;
Debug.DrawRay(chassis.position, chassisLook, Color.white);
Debug.DrawRay(chassis.position, left, Color.white);
Debug.DrawRay(chassis.position, right, Color.white);
//Raycasting
if(Physics.Raycast(transform.position, chassisLook, out chit, navSeeDistance)){
if(chit.transform.gameObject.layer == LayerUnpassable01){
pathBlocked = true;
inputBrake = true;
inputTorque = -100.0f;
if(rigb.velocity.sqrMagnitude <= 20.0f){
inputTorque = 0.0f;
}
}
}else{
// pathBlocked = false;
}
//
//This is where the car steers and AI inputs speed/torque in order to get to target.
if(pathBlocked == false){
inputSteer = relativeWaypointPos.x / relativeWaypointPos.magnitude;
if(Mathf.Abs(inputSteer)<0.5)
inputTorque = relativeWaypointPos.z / relativeWaypointPos.magnitude - Mathf.Abs(inputSteer);
else
inputTorque = 0.0f;