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.
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?
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.
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.