public void findNearest() { float lastDistance = Mathf.Infinity; float currentPosition; int placeHolder = 0; RaceManager rc = FindObjectOfType <RaceManager>(); _aiSplineScript = rc.orderedSplines[activeSpline].GetComponent <SplinePlus>(); _branchesAtStart = new Dictionary <int, Branch>(_aiSplineScript.SPData.DictBranches); foreach (KeyValuePair <int, Branch> entry in _branchesAtStart) { for (int j = 0; j < entry.Value.Vertices.Count; j++) { currentPosition = Vector3.Distance(entry.Value.Vertices[j], transform.position); if (closestVertex == Vector3.zero) { closestVertex = entry.Value.Vertices[j]; closestIndex = j; lastDistance = currentPosition; } else if (currentPosition <= lastDistance) { placeHolder = j; placeHolder = Mathf.Clamp(placeHolder + 5, 0, entry.Value.Vertices.Count - 1); vertexAim = entry.Value.Vertices[placeHolder]; lastDistance = currentPosition; closestVertex = vertexAim; closestIndex = placeHolder; } } } }
void Initialize() { // Cache Vehicle Input input = GetComponent <VehicleInput>(); // Cache a reference to our car's transform carTransform = transform; // cache the rigidbody for our car carRigidbody = GetComponent <Rigidbody>(); // cache the mass of our vehicle carMass = GetComponent <Rigidbody>().mass; // call to set up our wheels array setUpWheels(); // we set a COG here and lower the center of mass to a //negative value in Y axis to prevent car from flipping over carRigidbody.centerOfMass = new Vector3(0f, -1.0f, -0f); frontLeftRayCast = frontLeftWheel.GetComponentInParent <RaycastWheel>(); frontRightRayCast = frontRightWheel.GetComponentInParent <RaycastWheel>(); rearLeftRayCast = rearLeftWheel.GetComponentInParent <RaycastWheel>(); rearRightRayCast = rearRightWheel.GetComponentInParent <RaycastWheel>(); gravityDirection = -transform.up; lastSafePos = carTransform.position; rc = FindObjectOfType <RaceManager>(); if (GetComponent <VehicleInput>()) { //Sets ai spline to find/follow hotspotspline if (rc != null && rc.orderedSplines.Length != 0) { _aiSplineScript = rc.orderedSplines[activeSpline].GetComponent <SplinePlus>(); _branchesAtStart = new Dictionary <int, Branch>(_aiSplineScript.SPData.DictBranches); InvokeRepeating("findNearest", 0, 2); } } }
public void SwapSpline(SplinePlus newSpline, bool arena) { _branchesAtStart = new Dictionary <int, Branch>(newSpline.SPData.DictBranches); _inArena = arena; }
void Start() { Animator = GetComponent <Animator>(); SplinePlus = GetComponent <SplinePlus>(); }