Compare commits
No commits in common. "c7242dbe588fcd9d1cff53ef689f537a81663b7e" and "8e4303adb016fd24dadf5ab4ddac180c3a1d5001" have entirely different histories.
c7242dbe58
...
8e4303adb0
13 changed files with 448 additions and 1056 deletions
File diff suppressed because it is too large
Load diff
238
RunningLateGame/Assets/Scripts/AICar.cs
Normal file
238
RunningLateGame/Assets/Scripts/AICar.cs
Normal file
|
@ -0,0 +1,238 @@
|
||||||
|
/*
|
||||||
|
* author: ryan lin
|
||||||
|
* date: 30/7/2024
|
||||||
|
* description: making the car go to a game object's position
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System.Collections;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// making the car go to a game object's position
|
||||||
|
/// </summary>
|
||||||
|
public class AICar : MonoBehaviour
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// reference to the car model
|
||||||
|
/// </summary>
|
||||||
|
[SerializeField] private Transform carPosition;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// the radius of which the car can stop in
|
||||||
|
/// </summary>
|
||||||
|
[SerializeField] private float stoppingDistance;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// the speed of which the car needs to be at/under to when it is in the slowed state
|
||||||
|
/// </summary>
|
||||||
|
[SerializeField] private float slowingSpeed;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// the radius that the car switches to the slowed state
|
||||||
|
/// </summary>
|
||||||
|
[SerializeField] private float slowingDistance;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// the distance that the car is allowed to reverse
|
||||||
|
/// </summary>
|
||||||
|
[SerializeField] private float reverseDist;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// the acceleration input for the car script
|
||||||
|
/// </summary>
|
||||||
|
private float _accelerationInput;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// the angular input for the car script
|
||||||
|
/// </summary>
|
||||||
|
private float _angularDirection;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// reference to the car script
|
||||||
|
/// </summary>
|
||||||
|
private CarController _car;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// the current state the car is in for fsm
|
||||||
|
/// </summary>
|
||||||
|
private string _currentState;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// the distance that the car is from the target
|
||||||
|
/// </summary>
|
||||||
|
private float _distanceToTarget;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// the transform of the target
|
||||||
|
/// </summary>
|
||||||
|
private Transform _driveTarget;
|
||||||
|
|
||||||
|
private NextState _nextState;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// the turn input for the car script
|
||||||
|
/// </summary>
|
||||||
|
private float _turnInput;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// the car is in front or behind the target, a positive will be returned if the car is in front
|
||||||
|
/// </summary>
|
||||||
|
private float _verticalDirection;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// initialise values
|
||||||
|
/// </summary>
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
var hasChild = false;
|
||||||
|
var i = 0;
|
||||||
|
while (!hasChild)
|
||||||
|
{
|
||||||
|
var test = gameObject.transform.GetChild(i).gameObject;
|
||||||
|
if (test.name == "Target")
|
||||||
|
{
|
||||||
|
_driveTarget = test.transform;
|
||||||
|
hasChild = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_car = GetComponent<CarController>();
|
||||||
|
_nextState = NextState.Stopped;
|
||||||
|
_currentState = "Stopped";
|
||||||
|
StartCoroutine(_currentState);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// to update the next state value when it changes
|
||||||
|
/// </summary>
|
||||||
|
private void Update()
|
||||||
|
{
|
||||||
|
if (_nextState == NextState.Stopped)
|
||||||
|
_currentState = "Stopped";
|
||||||
|
else if (_nextState == NextState.Slowed)
|
||||||
|
_currentState = "Slowed";
|
||||||
|
else
|
||||||
|
_currentState = "Driving";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// is called at the end of states to call the next state
|
||||||
|
/// </summary>
|
||||||
|
private void ChangeState()
|
||||||
|
{
|
||||||
|
StartCoroutine(_currentState);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// a function that allows the car to steer
|
||||||
|
/// </summary>
|
||||||
|
private void Steering()
|
||||||
|
{
|
||||||
|
_angularDirection = Vector3.SignedAngle(carPosition.transform.forward,
|
||||||
|
(_driveTarget.position - carPosition.transform.position).normalized, Vector3.up);
|
||||||
|
if (_angularDirection < 0)
|
||||||
|
_turnInput = -1;
|
||||||
|
else
|
||||||
|
_turnInput = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// to put the car in a stopped state
|
||||||
|
/// </summary>
|
||||||
|
private IEnumerator Stopped()
|
||||||
|
{
|
||||||
|
while (_nextState != NextState.Stopped)
|
||||||
|
{
|
||||||
|
_distanceToTarget = Vector3.Distance(carPosition.position, _driveTarget.position);
|
||||||
|
_car.braking = true;
|
||||||
|
_accelerationInput = 0f;
|
||||||
|
_turnInput = 0f;
|
||||||
|
if (_distanceToTarget > stoppingDistance) _nextState = NextState.Slowed;
|
||||||
|
yield return new WaitForSeconds(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
ChangeState();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// to put the car in a slowed state
|
||||||
|
/// </summary>
|
||||||
|
private IEnumerator Slowed()
|
||||||
|
{
|
||||||
|
_car.braking = false;
|
||||||
|
while (_nextState != NextState.Slowed)
|
||||||
|
{
|
||||||
|
_verticalDirection = Vector3.Dot(carPosition.transform.forward,
|
||||||
|
(_driveTarget.position - carPosition.transform.position).normalized);
|
||||||
|
_distanceToTarget = Vector3.Distance(carPosition.position, _driveTarget.position);
|
||||||
|
if (_verticalDirection > 0)
|
||||||
|
{
|
||||||
|
if (carPosition.GetComponent<Rigidbody>().velocity.magnitude > slowingSpeed)
|
||||||
|
_accelerationInput = -1;
|
||||||
|
else
|
||||||
|
_accelerationInput = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (_distanceToTarget < reverseDist)
|
||||||
|
_accelerationInput = -1;
|
||||||
|
else
|
||||||
|
_accelerationInput = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Steering();
|
||||||
|
SlowedCheck();
|
||||||
|
_car.SetInputs(_accelerationInput, _turnInput);
|
||||||
|
yield return new WaitForEndOfFrame();
|
||||||
|
}
|
||||||
|
|
||||||
|
ChangeState();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// to put the car in a driving state
|
||||||
|
/// </summary>
|
||||||
|
private IEnumerator Driving()
|
||||||
|
{
|
||||||
|
_car.braking = false;
|
||||||
|
while (_nextState != NextState.Driving)
|
||||||
|
{
|
||||||
|
_verticalDirection = Vector3.Dot(carPosition.transform.forward,
|
||||||
|
(_driveTarget.position - carPosition.transform.position).normalized);
|
||||||
|
_distanceToTarget = Vector3.Distance(carPosition.position, _driveTarget.position);
|
||||||
|
_accelerationInput = 1;
|
||||||
|
|
||||||
|
|
||||||
|
Steering();
|
||||||
|
if (_distanceToTarget < slowingDistance) _nextState = NextState.Slowed;
|
||||||
|
_car.SetInputs(_accelerationInput, _turnInput);
|
||||||
|
yield return new WaitForEndOfFrame();
|
||||||
|
}
|
||||||
|
|
||||||
|
ChangeState();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// a function to check if the car should be a slowed state
|
||||||
|
/// </summary>
|
||||||
|
private void SlowedCheck()
|
||||||
|
{
|
||||||
|
if (_distanceToTarget < stoppingDistance) _nextState = NextState.Stopped;
|
||||||
|
|
||||||
|
if (_distanceToTarget > slowingDistance) _nextState = NextState.Driving;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// enum of states that the car can be in
|
||||||
|
/// </summary>
|
||||||
|
private enum NextState
|
||||||
|
{
|
||||||
|
Slowed,
|
||||||
|
Stopped,
|
||||||
|
Driving
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 0ad7b657ea6a4b94781a78d6f2b6f475
|
guid: bc82a40176164f02897928bd573bc2ca
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
95
RunningLateGame/Assets/Scripts/AIManager.cs
Normal file
95
RunningLateGame/Assets/Scripts/AIManager.cs
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
/*
|
||||||
|
* author: ryan lin
|
||||||
|
* date: 08/08/2024
|
||||||
|
* description: to cull and spawn AI people
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using Random = System.Random;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// to cull and spawn AI people
|
||||||
|
/// </summary>
|
||||||
|
public class AIManager : MonoBehaviour
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// a reference to the player
|
||||||
|
/// </summary>
|
||||||
|
public Transform player;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// the distance of which the AI would be "killed"
|
||||||
|
/// </summary>
|
||||||
|
public float cullingDistance;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// the prefab to spawn
|
||||||
|
/// </summary>
|
||||||
|
public GameObject aiPrefab;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// the maximum number of AI that can be spawned at any time
|
||||||
|
/// </summary>
|
||||||
|
public int maxAI;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// An array that contains the game objects of the AI objects
|
||||||
|
/// </summary>
|
||||||
|
private GameObject[] _ais;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// a temporary float to find the distance between the player and the AI
|
||||||
|
/// </summary>
|
||||||
|
private float _distance;
|
||||||
|
/// <summary>
|
||||||
|
/// AI Spawn locations
|
||||||
|
/// </summary>
|
||||||
|
[SerializeField]private List<Transform> aiSpawn;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// to start the manager loop
|
||||||
|
/// </summary>
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
StartCoroutine(Manager());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// to show the range in the inspector when the object is selected
|
||||||
|
/// </summary>
|
||||||
|
private void OnDrawGizmosSelected()
|
||||||
|
{
|
||||||
|
Gizmos.color = Color.yellow;
|
||||||
|
Gizmos.DrawWireSphere(player.position, cullingDistance);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// to allow the IEnumerator to destroy or instantiate AI
|
||||||
|
/// </summary>
|
||||||
|
private IEnumerator Manager()
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
// FIXME: feels weird
|
||||||
|
_ais = GameObject.FindGameObjectsWithTag("AIs");
|
||||||
|
if (_ais.Length < maxAI)
|
||||||
|
{
|
||||||
|
var rand = new Random();
|
||||||
|
var spawnNo=rand.Next(0, aiSpawn.Count);
|
||||||
|
|
||||||
|
var instance = Instantiate(aiPrefab, aiSpawn[spawnNo]);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var i in _ais)
|
||||||
|
{
|
||||||
|
_distance = Vector3.Distance(i.transform.position, player.position);
|
||||||
|
if (_distance > cullingDistance) Destroy(i.gameObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
yield return new WaitForSeconds(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: e1a5b97ac163ed54bb06c559615dfdd5
|
guid: 6ed3090768dbec24b922f887029b3132
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
|
@ -47,6 +47,11 @@ public class AICar : MonoBehaviour
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private float _angularDirection;
|
private float _angularDirection;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// reference to the car script
|
||||||
|
/// </summary>
|
||||||
|
private CarController _car;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// the current state the car is in for fsm
|
/// the current state the car is in for fsm
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -69,11 +74,6 @@ public class AICar : MonoBehaviour
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private float _turnInput;
|
private float _turnInput;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// reference to the car script
|
|
||||||
/// </summary>
|
|
||||||
private VehicleController _vehicle;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// the car is in front or behind the target, a positive will be returned if the car is in front
|
/// the car is in front or behind the target, a positive will be returned if the car is in front
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -100,7 +100,7 @@ public class AICar : MonoBehaviour
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_vehicle = GetComponent<VehicleController>();
|
_car = GetComponent<CarController>();
|
||||||
_nextState = NextState.Stopped;
|
_nextState = NextState.Stopped;
|
||||||
_currentState = "Stopped";
|
_currentState = "Stopped";
|
||||||
StartCoroutine(_currentState);
|
StartCoroutine(_currentState);
|
||||||
|
@ -148,7 +148,7 @@ public class AICar : MonoBehaviour
|
||||||
while (_nextState != NextState.Stopped)
|
while (_nextState != NextState.Stopped)
|
||||||
{
|
{
|
||||||
_distanceToTarget = Vector3.Distance(carPosition.position, _driveTarget.position);
|
_distanceToTarget = Vector3.Distance(carPosition.position, _driveTarget.position);
|
||||||
_vehicle.braking = true;
|
_car.braking = true;
|
||||||
_accelerationInput = 0f;
|
_accelerationInput = 0f;
|
||||||
_turnInput = 0f;
|
_turnInput = 0f;
|
||||||
if (_distanceToTarget > stoppingDistance) _nextState = NextState.Slowed;
|
if (_distanceToTarget > stoppingDistance) _nextState = NextState.Slowed;
|
||||||
|
@ -163,7 +163,7 @@ public class AICar : MonoBehaviour
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private IEnumerator Slowed()
|
private IEnumerator Slowed()
|
||||||
{
|
{
|
||||||
_vehicle.braking = false;
|
_car.braking = false;
|
||||||
while (_nextState != NextState.Slowed)
|
while (_nextState != NextState.Slowed)
|
||||||
{
|
{
|
||||||
_verticalDirection = Vector3.Dot(carPosition.transform.forward,
|
_verticalDirection = Vector3.Dot(carPosition.transform.forward,
|
||||||
|
@ -186,7 +186,7 @@ public class AICar : MonoBehaviour
|
||||||
|
|
||||||
Steering();
|
Steering();
|
||||||
SlowedCheck();
|
SlowedCheck();
|
||||||
_vehicle.SetInputs(_accelerationInput, _turnInput);
|
_car.SetInputs(_accelerationInput, _turnInput);
|
||||||
yield return new WaitForEndOfFrame();
|
yield return new WaitForEndOfFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,7 +198,7 @@ public class AICar : MonoBehaviour
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private IEnumerator Driving()
|
private IEnumerator Driving()
|
||||||
{
|
{
|
||||||
_vehicle.braking = false;
|
_car.braking = false;
|
||||||
while (_nextState != NextState.Driving)
|
while (_nextState != NextState.Driving)
|
||||||
{
|
{
|
||||||
_verticalDirection = Vector3.Dot(carPosition.transform.forward,
|
_verticalDirection = Vector3.Dot(carPosition.transform.forward,
|
||||||
|
@ -209,7 +209,7 @@ public class AICar : MonoBehaviour
|
||||||
|
|
||||||
Steering();
|
Steering();
|
||||||
if (_distanceToTarget < slowingDistance) _nextState = NextState.Slowed;
|
if (_distanceToTarget < slowingDistance) _nextState = NextState.Slowed;
|
||||||
_vehicle.SetInputs(_accelerationInput, _turnInput);
|
_car.SetInputs(_accelerationInput, _turnInput);
|
||||||
yield return new WaitForEndOfFrame();
|
yield return new WaitForEndOfFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,11 +35,6 @@ public class AIManager : MonoBehaviour
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int maxAI;
|
public int maxAI;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// AI Spawn locations
|
|
||||||
/// </summary>
|
|
||||||
[SerializeField] private List<Transform> aiSpawn;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An array that contains the game objects of the AI objects
|
/// An array that contains the game objects of the AI objects
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -49,6 +44,10 @@ public class AIManager : MonoBehaviour
|
||||||
/// a temporary float to find the distance between the player and the AI
|
/// a temporary float to find the distance between the player and the AI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private float _distance;
|
private float _distance;
|
||||||
|
/// <summary>
|
||||||
|
/// AI Spawn locations
|
||||||
|
/// </summary>
|
||||||
|
[SerializeField]private List<Transform> aiSpawn;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// to start the manager loop
|
/// to start the manager loop
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* author: ryan lin, mark joshwel
|
* author: ryan lin
|
||||||
* date: 06/08/2024
|
* date: 06/08/2024
|
||||||
* description: a controller for the car
|
* description: a controller for the car
|
||||||
*/
|
*/
|
||||||
|
@ -12,7 +12,7 @@ using UnityEngine;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// a controller for the car
|
/// a controller for the car
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class VehicleController : MonoBehaviour
|
public class CarController : MonoBehaviour
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// enum for if the wheel is the front or back wheel
|
/// enum for if the wheel is the front or back wheel
|
||||||
|
@ -51,12 +51,12 @@ public class VehicleController : MonoBehaviour
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// inputs for acceleration
|
/// inputs for acceleration
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SerializeField] private float currentAcceleration;
|
[SerializeField] private float _currentAcceleration;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// inputs for turning
|
/// inputs for turning
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SerializeField] private float currentTurn;
|
[SerializeField] private float _currentTurn;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// to move the car
|
/// to move the car
|
||||||
|
@ -73,23 +73,23 @@ public class VehicleController : MonoBehaviour
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void SetInputs(float forwardAmount, float turnAmount)
|
public void SetInputs(float forwardAmount, float turnAmount)
|
||||||
{
|
{
|
||||||
currentAcceleration = forwardAmount * motorTorque;
|
_currentAcceleration = forwardAmount * motorTorque;
|
||||||
currentTurn = turnAmount * turnAngle;
|
_currentTurn = turnAmount * turnAngle;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// to move the car forwards or backwards
|
/// to move the car forwards or backwards
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void Move()
|
public void Move()
|
||||||
{
|
{
|
||||||
foreach (var wheel in wheels)
|
foreach (var wheel in wheels)
|
||||||
wheel.wheelCollider.motorTorque = currentAcceleration;
|
wheel.wheelCollider.motorTorque = _currentAcceleration;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// to stop the car
|
/// to stop the car
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void Brake()
|
public void Brake()
|
||||||
{
|
{
|
||||||
if (braking)
|
if (braking)
|
||||||
foreach (var wheel in wheels)
|
foreach (var wheel in wheels)
|
||||||
|
@ -102,10 +102,14 @@ public class VehicleController : MonoBehaviour
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// to turn the car
|
/// to turn the car
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void Steering()
|
public void Steering()
|
||||||
{
|
{
|
||||||
foreach (var wheel in wheels.Where(wheel => wheel.axel == Axel.Front))
|
foreach (var wheel in wheels)
|
||||||
wheel.wheelCollider.steerAngle = currentTurn;
|
if (wheel.axel == Axel.Front)
|
||||||
|
{
|
||||||
|
wheel.wheelCollider.steerAngle = _currentTurn;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
|
@ -1,28 +0,0 @@
|
||||||
/*
|
|
||||||
* author: ryan lin, mark joshwel
|
|
||||||
* date: 15/08/2024
|
|
||||||
* description: common vehicular behaviour
|
|
||||||
*/
|
|
||||||
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// logic to move a vehicle to a target position
|
|
||||||
/// </summary>
|
|
||||||
public class CommonVehicle : MonoBehaviour
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// game object that the vehicle is moving towards
|
|
||||||
/// </summary>
|
|
||||||
[SerializeField] private GameObject targetWaypoint;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// enum of states that the vehicle can be in
|
|
||||||
/// </summary>
|
|
||||||
private enum State
|
|
||||||
{
|
|
||||||
Stopped,
|
|
||||||
Slowed,
|
|
||||||
Driving
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
/*
|
|
||||||
* author: mark joshwel
|
|
||||||
* date: 15/08/2024
|
|
||||||
* description: vehicular target
|
|
||||||
*/
|
|
||||||
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
public class VehicleWaypoint : MonoBehaviour
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// next vehicle target waypoint for the vehicle to move to
|
|
||||||
/// </summary>
|
|
||||||
[SerializeField] private GameObject nextTarget;
|
|
||||||
}
|
|
Reference in a new issue