Car AI questions...

Hi guys. I am here to ask one thing: how would I go about modifying seeksteer.js to use a relative path? I am sick of my cars traveling in a straight line one after the other, whereas in real life, cars tend to move the same direction, but relative to each other.

I have the script modified already to help make transitions to the next waypoint smoother, now all I need is to make the waypoint path relative, to make the cars more realistic.

Here’s the script BTW:

#pragma strict
var waypointContainer : GameObject;
var waypoints : Component[];
var waypointRadius : float = 1.5;
var damping : float = 0.1;
var loop : boolean = false;
var speed : float = 2.0;
var faceHeading : boolean = true;
var targetHeading : Vector3;
var currentHeading : Vector3;
private var targetwaypoint : int;

// Use this for initialization
function Start() {
   waypoints = waypointContainer.GetComponentsInChildren(Transform);
   currentHeading = transform.forward;
}
// calculates a new heading
var prev : Quaternion;
function Update() {
   var move : Vector3 = transform.forward * Random.Range(speed/2, speed*2);
   move.y = rigidbody.velocity.y;
   rigidbody.velocity = move;
   
   var look = waypoints[targetwaypoint].transform.position - transform.position;
   var rot = Quaternion.LookRotation(look);

   if(Vector3.Distance(transform.position,waypoints[targetwaypoint].transform.position)<=waypointRadius)
   {
     targetwaypoint++;
     if(targetwaypoint>=waypoints.Length)
     {
     targetwaypoint = 0;
     }
   }
   
   rot.eulerAngles.x = 0;
   transform.rotation = Quaternion.Lerp(prev,rot, 2*Time.deltaTime);
   prev = transform.rotation;
}

Note that my cars use velocity-based movement and not wheel colliders. :wink:

I Will not start modifying the script (i can but i wont(am Lazy)) but i can tell you what to do ! :slight_smile:

Create or add RayCast ! Draw 5 lines of Ray 2x at right 2x at left and 1 straight.

Car will not rush into wall and also it will not go straight(if its not a straight road :slight_smile: )

Also Read The Description !

Thank you so much man! I found what I was looking for! :slight_smile:

No problem :slight_smile:

Want to see my progress? I was able to get some sick AI! Of course, there’s the occasional pile-up still… :wink:

EDIT: Fixed majority of pile-ups by modding acceleration! :slight_smile:

I would be very interested to see your progress!

Show Tha Progress !

I once tried this script. 5 ray casts per fixed update seems rather expensive. tried a scene with script on 32 cars, and could only reach frames per second rates in the teens (15-20 fps). The vehicles were also behaving quite erratically and much of time unable to steer straight.

If you’ve used fewer ray casts, have you noticed any performance/precision tradeoffs?

Using ray cast kill some performance.

I’ve discovered that I can spread ray casts across different updates and achieve somewhat better frame rates and less erratic AI behavior. Ultimately, I would like to abandon ray casts in favor of grids.

@Fr33Ke :

Ok my notifications aren’t working again… Sorry guys! :smile:

For those who wanted to see my progress, head here: [WIP] Alternator Power: (New working title) Arcade racer for Windows 10, Android and SteamOS+Linux - Community Showcases - Unity Discussions

I will also say, that my cars no longer need accel mod, as I found the bug causing the steering mod to not work: it was the timer generating the random vector not working properly. :wink: