game(scripts): xml code comment todos

This commit is contained in:
Sc0rch-thinks 2024-08-11 05:40:22 +08:00
parent 359fd07a72
commit 711b7c901d
5 changed files with 97 additions and 89 deletions

View file

@ -10,7 +10,7 @@
using Random = System.Random; using Random = System.Random;
/// <summary> /// <summary>
/// TODO /// 'standard' npc ai behaviour
/// </summary> /// </summary>
public class AI : MonoBehaviour public class AI : MonoBehaviour
{ {

View file

@ -1,95 +1,86 @@
/* /*
* author: ryan lin * author: ryan lin
* date: 30/7/2024 * date: 30/7/2024
* description: vehicular ai behaviour * description: making the car go to a game object's position
*/ */
using System.Collections; using System.Collections;
using UnityEngine; using UnityEngine;
/// <summary> /// <summary>
/// TODO /// making the car go to a game object's position
/// </summary> /// </summary>
public class AICar : MonoBehaviour public class AICar : MonoBehaviour
{ {
/// <summary> /// <summary>
/// TODO /// reference to the car model
/// </summary> /// </summary>
[SerializeField] private Transform carPosition; [SerializeField] private Transform carPosition;
/// <summary> /// <summary>
/// TODO /// the radius of which the car can stop in
/// </summary> /// </summary>
[SerializeField] private float stoppingDistance; [SerializeField] private float stoppingDistance;
/// <summary> /// <summary>
/// TODO /// the speed of which the car needs to be at/under to when it is in the slowed state
/// </summary> /// </summary>
[SerializeField] private float slowingSpeed; [SerializeField] private float slowingSpeed;
/// <summary> /// <summary>
/// TODO /// the radius that the car switches to the slowed state
/// </summary> /// </summary>
[SerializeField] private float slowingDistance; [SerializeField] private float slowingDistance;
/// <summary> /// <summary>
/// TODO /// the distance that the car is allowed to reverse
/// </summary> /// </summary>
[SerializeField] private float reverseDist; [SerializeField] private float reverseDist;
/// <summary> /// <summary>
/// TODO /// the acceleration input for the car script
/// </summary> /// </summary>
private float _accelerationInput; private float _accelerationInput;
/// <summary> /// <summary>
/// TODO /// the angular input for the car script
/// </summary> /// </summary>
private float _angularDirection; private float _angularDirection;
/// <summary> /// <summary>
/// TODO /// reference to the car script
/// </summary> /// </summary>
private CarController _car; private CarController _car;
/// <summary> /// <summary>
/// TODO /// the current state the car is in for fsm
/// </summary> /// </summary>
private string _currentState; private string _currentState;
/// <summary> /// <summary>
/// TODO /// the distance that the car is from the target
/// </summary>
private Vector3 _dirToMove;
/// <summary>
/// TODO
/// </summary> /// </summary>
private float _distanceToTarget; private float _distanceToTarget;
/// <summary> /// <summary>
/// TODO /// the transform of the target
/// </summary> /// </summary>
private Transform _driveTarget; private Transform _driveTarget;
/// <summary> private NextState _nextState;
/// TODO
/// </summary>
// FIXME: use an enum or something
private string _nextState;
/// <summary> /// <summary>
/// TODO /// the turn input for the car script
/// </summary> /// </summary>
private float _turnInput; private float _turnInput;
/// <summary> /// <summary>
/// TODO /// the car is in front or behind the target, a positive will be returned if the car is in front
/// </summary> /// </summary>
private float _verticalDirection; private float _verticalDirection;
/// <summary> /// <summary>
/// TODO /// initialise values
/// </summary> /// </summary>
private void Awake() private void Awake()
{ {
@ -110,21 +101,26 @@ private void Awake()
} }
_car = GetComponent<CarController>(); _car = GetComponent<CarController>();
_currentState = "Stopped"; _nextState = NextState.Stopped;
_nextState = _currentState;
ChangeState(); ChangeState();
} }
/// <summary> /// <summary>
/// TODO /// to update the next state value when it changes
/// </summary> /// </summary>
private void Update() private void Update()
{ {
_currentState = _nextState; if (_nextState == NextState.Stopped)
_currentState = "Stopped";
else if (_nextState == NextState.Slowed)
_currentState = "Slowed";
else
_currentState = "Driving";
} }
/// <summary> /// <summary>
/// TODO /// is called at the end of states to call the next state
/// </summary> /// </summary>
private void ChangeState() private void ChangeState()
{ {
@ -132,7 +128,7 @@ private void ChangeState()
} }
/// <summary> /// <summary>
/// TODO /// a function that allows the car to steer
/// </summary> /// </summary>
private void Steering() private void Steering()
{ {
@ -145,17 +141,17 @@ private void Steering()
} }
/// <summary> /// <summary>
/// TODO /// to put the car in a stopped state
/// </summary> /// </summary>
private IEnumerator Stopped() private IEnumerator Stopped()
{ {
while (_currentState == "Stopped") while (_nextState != NextState.Stopped)
{ {
_distanceToTarget = Vector3.Distance(carPosition.position, _driveTarget.position); _distanceToTarget = Vector3.Distance(carPosition.position, _driveTarget.position);
_car.braking = true; _car.braking = true;
_accelerationInput = 0f; _accelerationInput = 0f;
_turnInput = 0f; _turnInput = 0f;
if (_distanceToTarget > stoppingDistance) _nextState = "Slowed"; if (_distanceToTarget > stoppingDistance) _nextState = NextState.Slowed;
yield return new WaitForSeconds(1); yield return new WaitForSeconds(1);
} }
@ -163,12 +159,12 @@ private IEnumerator Stopped()
} }
/// <summary> /// <summary>
/// TODO /// to put the car in a slowed state
/// </summary> /// </summary>
private IEnumerator Slowed() private IEnumerator Slowed()
{ {
_car.braking = false; _car.braking = false;
while (_currentState == "Slowed") while (_nextState != NextState.Slowed)
{ {
_verticalDirection = Vector3.Dot(carPosition.transform.forward, _verticalDirection = Vector3.Dot(carPosition.transform.forward,
(_driveTarget.position - carPosition.transform.position).normalized); (_driveTarget.position - carPosition.transform.position).normalized);
@ -198,12 +194,12 @@ private IEnumerator Slowed()
} }
/// <summary> /// <summary>
/// TODO /// to put the car in a driving state
/// </summary> /// </summary>
private IEnumerator Driving() private IEnumerator Driving()
{ {
_car.braking = false; _car.braking = false;
while (_currentState == "Driving") while (_nextState != NextState.Driving)
{ {
_verticalDirection = Vector3.Dot(carPosition.transform.forward, _verticalDirection = Vector3.Dot(carPosition.transform.forward,
(_driveTarget.position - carPosition.transform.position).normalized); (_driveTarget.position - carPosition.transform.position).normalized);
@ -212,7 +208,7 @@ private IEnumerator Driving()
Steering(); Steering();
if (_distanceToTarget < slowingDistance) _nextState = "Slowed"; if (_distanceToTarget < slowingDistance) _nextState = NextState.Slowed;
_car.SetInputs(_accelerationInput, _turnInput); _car.SetInputs(_accelerationInput, _turnInput);
yield return new WaitForEndOfFrame(); yield return new WaitForEndOfFrame();
} }
@ -221,12 +217,22 @@ private IEnumerator Driving()
} }
/// <summary> /// <summary>
/// TODO /// a function to check if the car should be a slowed state
/// </summary> /// </summary>
private void SlowedCheck() private void SlowedCheck()
{ {
if (_distanceToTarget < stoppingDistance) _nextState = "Stopped"; if (_distanceToTarget < stoppingDistance) _nextState = NextState.Stopped;
if (_distanceToTarget > slowingDistance) _nextState = "Driving"; if (_distanceToTarget > slowingDistance)_nextState = NextState.Driving;
}
/// <summary>
/// enum of states that the car can be in
/// </summary>
private enum NextState
{
Slowed,
Stopped,
Driving
} }
} }

View file

@ -1,46 +1,48 @@
/* /*
* author: ryan lin * author: ryan lin
* date: TODO * date: 08/08/2024
* description: TODO * description: to cull and spawn AI people
*/ */
using System.Collections; using System.Collections;
using UnityEngine; using UnityEngine;
/// <summary>
/// to cull and spawn AI people
/// </summary>
public class AIManager : MonoBehaviour public class AIManager : MonoBehaviour
{ {
/// <summary> /// <summary>
/// TODO /// a reference to the player
/// </summary> /// </summary>
public Transform player; public Transform player;
/// <summary> /// <summary>
/// TODO /// the distance of which the AI would be "killed"
/// </summary> /// </summary>
public float cullingDistance; public float cullingDistance;
/// <summary> /// <summary>
/// TODO /// the prefab to spawn
/// </summary> /// </summary>
public GameObject aiPrefab; public GameObject aiPrefab;
/// <summary> /// <summary>
/// TODO /// the maximum number of AI that can be spawned at any time
/// </summary> /// </summary>
public int maxAI; public int maxAI;
/// <summary> /// <summary>
/// TODO /// An array that contains the game objects of the AI objects
/// </summary> /// </summary>
private GameObject[] _ais; private GameObject[] _ais;
/// <summary> /// <summary>
/// TODO /// a temporary float to find the distance between the player and the AI
/// </summary> /// </summary>
private float _distance; private float _distance;
/// <summary> /// <summary>
/// TODO /// to start the
/// </summary> /// </summary>
private void Start() private void Start()
{ {
@ -48,16 +50,16 @@ private void Start()
} }
/// <summary> /// <summary>
/// TODO /// to show the range in the inspector
/// </summary> /// </summary>
private void OnDrawGizmos() private void OnDrawGizmosSelected()
{ {
Gizmos.color = Color.yellow; Gizmos.color = Color.yellow;
Gizmos.DrawWireSphere(player.position, cullingDistance); Gizmos.DrawWireSphere(player.position, cullingDistance);
} }
/// <summary> /// <summary>
/// TODO /// to allow the IEnumerator to destroy or instantiate AI
/// </summary> /// </summary>
private IEnumerator Manager() private IEnumerator Manager()
{ {
@ -78,6 +80,7 @@ private IEnumerator Manager()
yield return new WaitForSeconds(1); yield return new WaitForSeconds(1);
} }
// TODO: iterator never returns? is this intended?
} }
} }

View file

@ -1,21 +1,22 @@
/* /*
* author: ryan lin * author: ryan lin
* date: TODO * date: 06/08/2024
* description: TODO * description: a controller for the car
*/ */
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using UnityEngine; using UnityEngine;
using UnityEngine.Serialization;
/// <summary> /// <summary>
/// TODO /// a controller for the car
/// </summary> /// </summary>
public class CarController : MonoBehaviour public class CarController : MonoBehaviour
{ {
/// <summary> /// <summary>
/// TODO /// enum for if the wheel is the front or back wheel
/// </summary> /// </summary>
public enum Axel public enum Axel
{ {
@ -24,42 +25,42 @@ public enum Axel
} }
/// <summary> /// <summary>
/// TODO /// a value for the motor torque that the wheels have when speeding up
/// </summary> /// </summary>
public float acceleration; public float motorTorque;
/// <summary> /// <summary>
/// TODO /// the angle that the wheels turn when the car turns
/// </summary> /// </summary>
public float turnAngle; public float turnAngle;
/// <summary> /// <summary>
/// TODO /// a list to input the different wheels
/// </summary> /// </summary>
public List<Wheel> wheels; public List<Wheel> wheels;
/// <summary> /// <summary>
/// TODO /// the force the wheel exerts when it brakes
/// </summary> /// </summary>
public float brakeForce; public float brakeForce;
/// <summary> /// <summary>
/// TODO /// a bool to brake the car
/// </summary> /// </summary>
public bool braking; public bool braking;
/// <summary> /// <summary>
/// TODO /// inputs for acceleration
/// </summary> /// </summary>
private float _currentAcceleration; private float _currentAcceleration;
/// <summary> /// <summary>
/// TODO /// inputs for turning
/// </summary> /// </summary>
private float _currentTurn; private float _currentTurn;
/// <summary> /// <summary>
/// TODO /// to move the car
/// </summary> /// </summary>
private void FixedUpdate() private void FixedUpdate()
{ {
@ -69,16 +70,16 @@ private void FixedUpdate()
} }
/// <summary> /// <summary>
/// TODO /// for other scripts to set the inputs
/// </summary> /// </summary>
public void SetInputs(float forwardAmount, float turnAmount) public void SetInputs(float forwardAmount, float turnAmount)
{ {
_currentAcceleration = forwardAmount * acceleration; _currentAcceleration = forwardAmount * motorTorque;
_currentTurn = turnAmount * turnAngle; _currentTurn = turnAmount * turnAngle;
} }
/// <summary> /// <summary>
/// TODO /// to move the car forwards or backwards
/// </summary> /// </summary>
public void Move() public void Move()
{ {
@ -86,7 +87,7 @@ public void Move()
} }
/// <summary> /// <summary>
/// TODO /// to stop the car
/// </summary> /// </summary>
public void Brake() public void Brake()
{ {
@ -99,7 +100,7 @@ public void Brake()
} }
/// <summary> /// <summary>
/// TODO /// to turn the car
/// </summary> /// </summary>
public void Steering() public void Steering()
{ {
@ -108,9 +109,8 @@ public void Steering()
} }
/// <summary> /// <summary>
/// TODO /// a struct to display the wheels in the inspector
/// </summary> /// </summary>
// NOTE: once again, why is this at the bottom lol
[Serializable] [Serializable]
public struct Wheel public struct Wheel
{ {

View file

@ -10,12 +10,12 @@
using UnityEngine; using UnityEngine;
/// <summary> /// <summary>
/// TODO /// door interaction and animation
/// </summary> /// </summary>
public class Door : CommonInteractable public class Door : CommonInteractable
{ {
/// <summary> /// <summary>
/// TODO /// the type of door that is being used
/// </summary> /// </summary>
public enum DoorType public enum DoorType
{ {
@ -24,32 +24,32 @@ public enum DoorType
} }
/// <summary> /// <summary>
/// TODO /// the list of doors that are being used
/// </summary> /// </summary>
public List<DoorInput> doors; public List<DoorInput> doors;
/// <summary> /// <summary>
/// TODO /// the duration of the door opening
/// </summary> /// </summary>
public float duration; public float duration;
/// <summary> /// <summary>
/// TODO /// the animation curve of the door opening
/// </summary> /// </summary>
public AnimationCurve curve; public AnimationCurve curve;
/// <summary> /// <summary>
/// TODO /// a bool to check if the door is open
/// </summary> /// </summary>
private bool _isOpen; private bool _isOpen;
/// <summary> /// <summary>
/// TODO /// a bool to check if the door is opening
/// </summary> /// </summary>
private bool _opening; private bool _opening;
/// <summary> /// <summary>
/// TODO /// to interact with the door
/// </summary> /// </summary>
public override void Interact() public override void Interact()
{ {
@ -57,7 +57,7 @@ public override void Interact()
} }
/// <summary> /// <summary>
/// TODO /// to open the door
/// </summary> /// </summary>
private IEnumerator OpenDoor() private IEnumerator OpenDoor()
{ {
@ -104,9 +104,8 @@ private IEnumerator OpenDoor()
} }
/// <summary> /// <summary>
/// TODO /// a struct to hold the door input
/// </summary> /// </summary>
// NOTE: why is this at the bottom lol
[Serializable] [Serializable]
public struct DoorInput public struct DoorInput
{ {