Compare commits
2 commits
8e4303adb0
...
c7242dbe58
Author | SHA1 | Date | |
---|---|---|---|
Mark Joshwel | c7242dbe58 | ||
Mark Joshwel | 72596f0b07 |
File diff suppressed because it is too large
Load diff
|
@ -1,238 +0,0 @@
|
||||||
/*
|
|
||||||
* 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,95 +0,0 @@
|
||||||
/*
|
|
||||||
* 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -47,11 +47,6 @@ 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>
|
||||||
|
@ -74,6 +69,11 @@ 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 @@ private void Awake()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_car = GetComponent<CarController>();
|
_vehicle = GetComponent<VehicleController>();
|
||||||
_nextState = NextState.Stopped;
|
_nextState = NextState.Stopped;
|
||||||
_currentState = "Stopped";
|
_currentState = "Stopped";
|
||||||
StartCoroutine(_currentState);
|
StartCoroutine(_currentState);
|
||||||
|
@ -148,7 +148,7 @@ private IEnumerator Stopped()
|
||||||
while (_nextState != NextState.Stopped)
|
while (_nextState != NextState.Stopped)
|
||||||
{
|
{
|
||||||
_distanceToTarget = Vector3.Distance(carPosition.position, _driveTarget.position);
|
_distanceToTarget = Vector3.Distance(carPosition.position, _driveTarget.position);
|
||||||
_car.braking = true;
|
_vehicle.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 @@ private IEnumerator Stopped()
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private IEnumerator Slowed()
|
private IEnumerator Slowed()
|
||||||
{
|
{
|
||||||
_car.braking = false;
|
_vehicle.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 @@ private IEnumerator Slowed()
|
||||||
|
|
||||||
Steering();
|
Steering();
|
||||||
SlowedCheck();
|
SlowedCheck();
|
||||||
_car.SetInputs(_accelerationInput, _turnInput);
|
_vehicle.SetInputs(_accelerationInput, _turnInput);
|
||||||
yield return new WaitForEndOfFrame();
|
yield return new WaitForEndOfFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,7 +198,7 @@ private IEnumerator Slowed()
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private IEnumerator Driving()
|
private IEnumerator Driving()
|
||||||
{
|
{
|
||||||
_car.braking = false;
|
_vehicle.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 @@ private IEnumerator Driving()
|
||||||
|
|
||||||
Steering();
|
Steering();
|
||||||
if (_distanceToTarget < slowingDistance) _nextState = NextState.Slowed;
|
if (_distanceToTarget < slowingDistance) _nextState = NextState.Slowed;
|
||||||
_car.SetInputs(_accelerationInput, _turnInput);
|
_vehicle.SetInputs(_accelerationInput, _turnInput);
|
||||||
yield return new WaitForEndOfFrame();
|
yield return new WaitForEndOfFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,11 @@ 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>
|
||||||
|
@ -44,10 +49,6 @@ 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
|
||||||
|
@ -78,8 +79,8 @@ private IEnumerator Manager()
|
||||||
if (_ais.Length < maxAI)
|
if (_ais.Length < maxAI)
|
||||||
{
|
{
|
||||||
var rand = new Random();
|
var rand = new Random();
|
||||||
var spawnNo=rand.Next(0, aiSpawn.Count);
|
var spawnNo = rand.Next(0, aiSpawn.Count);
|
||||||
|
|
||||||
var instance = Instantiate(aiPrefab, aiSpawn[spawnNo]);
|
var instance = Instantiate(aiPrefab, aiSpawn[spawnNo]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
28
RunningLateGame/Assets/Scripts/CommonVehicle.cs
Normal file
28
RunningLateGame/Assets/Scripts/CommonVehicle.cs
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/*
|
||||||
|
* 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,5 +1,5 @@
|
||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: bc82a40176164f02897928bd573bc2ca
|
guid: e1a5b97ac163ed54bb06c559615dfdd5
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
|
@ -462,21 +462,21 @@ public void ClearInteractionPrompt()
|
||||||
public void ProperlyEndRun()
|
public void ProperlyEndRun()
|
||||||
{
|
{
|
||||||
SetDisplayState(DisplayState.OverlayCompleteUnderTimeMenu);
|
SetDisplayState(DisplayState.OverlayCompleteUnderTimeMenu);
|
||||||
|
|
||||||
var ui = guiCompletedMenuObject.GetComponent<UIDocument>()?.rootVisualElement;
|
var ui = guiCompletedMenuObject.GetComponent<UIDocument>()?.rootVisualElement;
|
||||||
var timeLabel = ui.Q<Label>("FinalTimeLabel");
|
var timeLabel = ui.Q<Label>("FinalTimeLabel");
|
||||||
var timeScore = ui.Q<Label>("FinalScoreLabel");
|
var timeScore = ui.Q<Label>("FinalScoreLabel");
|
||||||
var timeGrade = ui.Q<Label>("FinalGradeLabel");
|
var timeGrade = ui.Q<Label>("FinalGradeLabel");
|
||||||
|
|
||||||
// calculate a score between 0-1000 and grade (S, A, B, C, D)
|
// calculate a score between 0-1000 and grade (S, A, B, C, D)
|
||||||
// if you finish the run in 2.5 minutes, you get a 1000
|
// if you finish the run in 2.5 minutes, you get a 1000
|
||||||
// from 2.5 to 5 minutes, the score goes down to 0
|
// from 2.5 to 5 minutes, the score goes down to 0
|
||||||
|
|
||||||
// scoring parameters
|
// scoring parameters
|
||||||
const float maxScore = 1000f;
|
const float maxScore = 1000f;
|
||||||
const float maxTimeForMaxScore = 15f; // 2.5 minutes
|
const float maxTimeForMaxScore = 15f; // 2.5 minutes
|
||||||
const float maxTimeForMinScore = 180f; // 5 minutes
|
const float maxTimeForMinScore = 180f; // 5 minutes
|
||||||
|
|
||||||
var score = _elapsedRunTime switch
|
var score = _elapsedRunTime switch
|
||||||
{
|
{
|
||||||
<= maxTimeForMaxScore => maxScore,
|
<= maxTimeForMaxScore => maxScore,
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class LiftController : MonoBehaviour
|
||||||
/// the target position of the lift
|
/// the target position of the lift
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private Vector3 _target;
|
private Vector3 _target;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// initialisation function
|
/// initialisation function
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* author: ryan lin
|
* author: ryan lin, mark joshwel
|
||||||
* date: 06/08/2024
|
* date: 06/08/2024
|
||||||
* description: a controller for the car
|
* description: a controller for the car
|
||||||
*/
|
*/
|
||||||
|
@ -12,7 +12,7 @@
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// a controller for the car
|
/// a controller for the car
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class CarController : MonoBehaviour
|
public class VehicleController : 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 enum Axel
|
||||||
/// <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 @@ private void FixedUpdate()
|
||||||
/// </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>
|
||||||
public void Move()
|
private 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>
|
||||||
public void Brake()
|
private void Brake()
|
||||||
{
|
{
|
||||||
if (braking)
|
if (braking)
|
||||||
foreach (var wheel in wheels)
|
foreach (var wheel in wheels)
|
||||||
|
@ -102,14 +102,10 @@ public void Brake()
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// to turn the car
|
/// to turn the car
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Steering()
|
private void Steering()
|
||||||
{
|
{
|
||||||
foreach (var wheel in wheels)
|
foreach (var wheel in wheels.Where(wheel => wheel.axel == Axel.Front))
|
||||||
if (wheel.axel == Axel.Front)
|
wheel.wheelCollider.steerAngle = currentTurn;
|
||||||
{
|
|
||||||
wheel.wheelCollider.steerAngle = _currentTurn;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
15
RunningLateGame/Assets/Scripts/VehicleWaypoint.cs
Normal file
15
RunningLateGame/Assets/Scripts/VehicleWaypoint.cs
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 6ed3090768dbec24b922f887029b3132
|
guid: 0ad7b657ea6a4b94781a78d6f2b6f475
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
Reference in a new issue