game(scripts): xml code comment todos
This commit is contained in:
parent
359fd07a72
commit
711b7c901d
5 changed files with 97 additions and 89 deletions
|
@ -10,7 +10,7 @@ using UnityEngine.AI;
|
|||
using Random = System.Random;
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// 'standard' npc ai behaviour
|
||||
/// </summary>
|
||||
public class AI : MonoBehaviour
|
||||
{
|
||||
|
|
|
@ -1,95 +1,86 @@
|
|||
/*
|
||||
* author: ryan lin
|
||||
* date: 30/7/2024
|
||||
* description: vehicular ai behaviour
|
||||
* description: making the car go to a game object's position
|
||||
*/
|
||||
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// making the car go to a game object's position
|
||||
/// </summary>
|
||||
public class AICar : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// reference to the car model
|
||||
/// </summary>
|
||||
[SerializeField] private Transform carPosition;
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// the radius of which the car can stop in
|
||||
/// </summary>
|
||||
[SerializeField] private float stoppingDistance;
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// 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>
|
||||
/// TODO
|
||||
/// the radius that the car switches to the slowed state
|
||||
/// </summary>
|
||||
[SerializeField] private float slowingDistance;
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// the distance that the car is allowed to reverse
|
||||
/// </summary>
|
||||
[SerializeField] private float reverseDist;
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// the acceleration input for the car script
|
||||
/// </summary>
|
||||
private float _accelerationInput;
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// the angular input for the car script
|
||||
/// </summary>
|
||||
private float _angularDirection;
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// reference to the car script
|
||||
/// </summary>
|
||||
private CarController _car;
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// the current state the car is in for fsm
|
||||
/// </summary>
|
||||
private string _currentState;
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// </summary>
|
||||
private Vector3 _dirToMove;
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// the distance that the car is from the target
|
||||
/// </summary>
|
||||
private float _distanceToTarget;
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// the transform of the target
|
||||
/// </summary>
|
||||
private Transform _driveTarget;
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// </summary>
|
||||
// FIXME: use an enum or something
|
||||
private string _nextState;
|
||||
private NextState _nextState;
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// the turn input for the car script
|
||||
/// </summary>
|
||||
private float _turnInput;
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// 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>
|
||||
/// TODO
|
||||
/// initialise values
|
||||
/// </summary>
|
||||
private void Awake()
|
||||
{
|
||||
|
@ -110,21 +101,26 @@ public class AICar : MonoBehaviour
|
|||
}
|
||||
|
||||
_car = GetComponent<CarController>();
|
||||
_currentState = "Stopped";
|
||||
_nextState = _currentState;
|
||||
_nextState = NextState.Stopped;
|
||||
|
||||
ChangeState();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// to update the next state value when it changes
|
||||
/// </summary>
|
||||
private void Update()
|
||||
{
|
||||
_currentState = _nextState;
|
||||
if (_nextState == NextState.Stopped)
|
||||
_currentState = "Stopped";
|
||||
else if (_nextState == NextState.Slowed)
|
||||
_currentState = "Slowed";
|
||||
else
|
||||
_currentState = "Driving";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// is called at the end of states to call the next state
|
||||
/// </summary>
|
||||
private void ChangeState()
|
||||
{
|
||||
|
@ -132,7 +128,7 @@ public class AICar : MonoBehaviour
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// a function that allows the car to steer
|
||||
/// </summary>
|
||||
private void Steering()
|
||||
{
|
||||
|
@ -145,17 +141,17 @@ public class AICar : MonoBehaviour
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// to put the car in a stopped state
|
||||
/// </summary>
|
||||
private IEnumerator Stopped()
|
||||
{
|
||||
while (_currentState == "Stopped")
|
||||
while (_nextState != NextState.Stopped)
|
||||
{
|
||||
_distanceToTarget = Vector3.Distance(carPosition.position, _driveTarget.position);
|
||||
_car.braking = true;
|
||||
_accelerationInput = 0f;
|
||||
_turnInput = 0f;
|
||||
if (_distanceToTarget > stoppingDistance) _nextState = "Slowed";
|
||||
if (_distanceToTarget > stoppingDistance) _nextState = NextState.Slowed;
|
||||
yield return new WaitForSeconds(1);
|
||||
}
|
||||
|
||||
|
@ -163,12 +159,12 @@ public class AICar : MonoBehaviour
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// to put the car in a slowed state
|
||||
/// </summary>
|
||||
private IEnumerator Slowed()
|
||||
{
|
||||
_car.braking = false;
|
||||
while (_currentState == "Slowed")
|
||||
while (_nextState != NextState.Slowed)
|
||||
{
|
||||
_verticalDirection = Vector3.Dot(carPosition.transform.forward,
|
||||
(_driveTarget.position - carPosition.transform.position).normalized);
|
||||
|
@ -198,12 +194,12 @@ public class AICar : MonoBehaviour
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// to put the car in a driving state
|
||||
/// </summary>
|
||||
private IEnumerator Driving()
|
||||
{
|
||||
_car.braking = false;
|
||||
while (_currentState == "Driving")
|
||||
while (_nextState != NextState.Driving)
|
||||
{
|
||||
_verticalDirection = Vector3.Dot(carPosition.transform.forward,
|
||||
(_driveTarget.position - carPosition.transform.position).normalized);
|
||||
|
@ -212,7 +208,7 @@ public class AICar : MonoBehaviour
|
|||
|
||||
|
||||
Steering();
|
||||
if (_distanceToTarget < slowingDistance) _nextState = "Slowed";
|
||||
if (_distanceToTarget < slowingDistance) _nextState = NextState.Slowed;
|
||||
_car.SetInputs(_accelerationInput, _turnInput);
|
||||
yield return new WaitForEndOfFrame();
|
||||
}
|
||||
|
@ -221,12 +217,22 @@ public class AICar : MonoBehaviour
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// a function to check if the car should be a slowed state
|
||||
/// </summary>
|
||||
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
|
||||
}
|
||||
}
|
|
@ -1,46 +1,48 @@
|
|||
/*
|
||||
* author: ryan lin
|
||||
* date: TODO
|
||||
* description: TODO
|
||||
* date: 08/08/2024
|
||||
* description: to cull and spawn AI people
|
||||
*/
|
||||
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// to cull and spawn AI people
|
||||
/// </summary>
|
||||
public class AIManager : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// a reference to the player
|
||||
/// </summary>
|
||||
public Transform player;
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// the distance of which the AI would be "killed"
|
||||
/// </summary>
|
||||
public float cullingDistance;
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// the prefab to spawn
|
||||
/// </summary>
|
||||
public GameObject aiPrefab;
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// the maximum number of AI that can be spawned at any time
|
||||
/// </summary>
|
||||
public int maxAI;
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// An array that contains the game objects of the AI objects
|
||||
/// </summary>
|
||||
private GameObject[] _ais;
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// a temporary float to find the distance between the player and the AI
|
||||
/// </summary>
|
||||
private float _distance;
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// to start the
|
||||
/// </summary>
|
||||
private void Start()
|
||||
{
|
||||
|
@ -48,16 +50,16 @@ public class AIManager : MonoBehaviour
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// to show the range in the inspector
|
||||
/// </summary>
|
||||
private void OnDrawGizmos()
|
||||
private void OnDrawGizmosSelected()
|
||||
{
|
||||
Gizmos.color = Color.yellow;
|
||||
Gizmos.DrawWireSphere(player.position, cullingDistance);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// to allow the IEnumerator to destroy or instantiate AI
|
||||
/// </summary>
|
||||
private IEnumerator Manager()
|
||||
{
|
||||
|
@ -78,6 +80,7 @@ public class AIManager : MonoBehaviour
|
|||
|
||||
yield return new WaitForSeconds(1);
|
||||
}
|
||||
// TODO: iterator never returns? is this intended?
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,21 +1,22 @@
|
|||
/*
|
||||
* author: ryan lin
|
||||
* date: TODO
|
||||
* description: TODO
|
||||
* date: 06/08/2024
|
||||
* description: a controller for the car
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// a controller for the car
|
||||
/// </summary>
|
||||
public class CarController : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// enum for if the wheel is the front or back wheel
|
||||
/// </summary>
|
||||
public enum Axel
|
||||
{
|
||||
|
@ -24,42 +25,42 @@ public class CarController : MonoBehaviour
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// a value for the motor torque that the wheels have when speeding up
|
||||
/// </summary>
|
||||
public float acceleration;
|
||||
public float motorTorque;
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// the angle that the wheels turn when the car turns
|
||||
/// </summary>
|
||||
public float turnAngle;
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// a list to input the different wheels
|
||||
/// </summary>
|
||||
public List<Wheel> wheels;
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// the force the wheel exerts when it brakes
|
||||
/// </summary>
|
||||
public float brakeForce;
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// a bool to brake the car
|
||||
/// </summary>
|
||||
public bool braking;
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// inputs for acceleration
|
||||
/// </summary>
|
||||
private float _currentAcceleration;
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// inputs for turning
|
||||
/// </summary>
|
||||
private float _currentTurn;
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// to move the car
|
||||
/// </summary>
|
||||
private void FixedUpdate()
|
||||
{
|
||||
|
@ -69,16 +70,16 @@ public class CarController : MonoBehaviour
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// for other scripts to set the inputs
|
||||
/// </summary>
|
||||
public void SetInputs(float forwardAmount, float turnAmount)
|
||||
{
|
||||
_currentAcceleration = forwardAmount * acceleration;
|
||||
_currentAcceleration = forwardAmount * motorTorque;
|
||||
_currentTurn = turnAmount * turnAngle;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// to move the car forwards or backwards
|
||||
/// </summary>
|
||||
public void Move()
|
||||
{
|
||||
|
@ -86,7 +87,7 @@ public class CarController : MonoBehaviour
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// to stop the car
|
||||
/// </summary>
|
||||
public void Brake()
|
||||
{
|
||||
|
@ -99,7 +100,7 @@ public class CarController : MonoBehaviour
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// to turn the car
|
||||
/// </summary>
|
||||
public void Steering()
|
||||
{
|
||||
|
@ -108,9 +109,8 @@ public class CarController : MonoBehaviour
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// a struct to display the wheels in the inspector
|
||||
/// </summary>
|
||||
// NOTE: once again, why is this at the bottom lol
|
||||
[Serializable]
|
||||
public struct Wheel
|
||||
{
|
||||
|
|
|
@ -10,12 +10,12 @@ using System.Collections.Generic;
|
|||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// door interaction and animation
|
||||
/// </summary>
|
||||
public class Door : CommonInteractable
|
||||
{
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// the type of door that is being used
|
||||
/// </summary>
|
||||
public enum DoorType
|
||||
{
|
||||
|
@ -24,32 +24,32 @@ public class Door : CommonInteractable
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// the list of doors that are being used
|
||||
/// </summary>
|
||||
public List<DoorInput> doors;
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// the duration of the door opening
|
||||
/// </summary>
|
||||
public float duration;
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// the animation curve of the door opening
|
||||
/// </summary>
|
||||
public AnimationCurve curve;
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// a bool to check if the door is open
|
||||
/// </summary>
|
||||
private bool _isOpen;
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// a bool to check if the door is opening
|
||||
/// </summary>
|
||||
private bool _opening;
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// to interact with the door
|
||||
/// </summary>
|
||||
public override void Interact()
|
||||
{
|
||||
|
@ -57,7 +57,7 @@ public class Door : CommonInteractable
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// to open the door
|
||||
/// </summary>
|
||||
private IEnumerator OpenDoor()
|
||||
{
|
||||
|
@ -104,9 +104,8 @@ public class Door : CommonInteractable
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// a struct to hold the door input
|
||||
/// </summary>
|
||||
// NOTE: why is this at the bottom lol
|
||||
[Serializable]
|
||||
public struct DoorInput
|
||||
{
|
||||
|
|
Reference in a new issue