Add AI Controller

This commit is contained in:
2019-10-04 21:28:32 +02:00
parent db9116cfdc
commit 7ac7e4fa89
6 changed files with 1029 additions and 19 deletions

View File

@@ -4,6 +4,7 @@ using UnityEngine;
public class PlayerController : MonoBehaviour
{
public bool aiControlled = false;
public string playerNumber;
public bool useController = false;
public float rotationSpeed = 100;
@@ -18,12 +19,16 @@ public class PlayerController : MonoBehaviour
public Vector2 pitchModifier;
private AudioSource audioSource;
private AIController aiController;
// Start is called before the first frame update
void Start()
{
this.audioSource = this.forceZone.transform.GetComponent<AudioSource>();
this.rb = GetComponent<Rigidbody>();
if (this.aiControlled)
{
this.aiController = GetComponent<AIController>();
}
}
// Update is called once per frame
@@ -31,6 +36,15 @@ public class PlayerController : MonoBehaviour
{
float rotationDirection = Input.GetAxis("Horizontal" + this.playerNumber);
float movementDirection = Input.GetAxis("Vertical" + this.playerNumber);
float[] aiInput = new float[3];
//Override any inputs if this instance is to be controlled by AI
if (this.aiControlled)
{
aiInput = this.aiController.GetInputs();
rotationDirection = aiInput[AiInputs.HORIZONTAL];
movementDirection = aiInput[AiInputs.VERTICAL];
}
if (this.useController) {
//Debug.Log(Input.GetAxis("VerticalBack" + this.playerNumber));
@@ -62,7 +76,7 @@ public class PlayerController : MonoBehaviour
}
//Boost
if (Input.GetButtonDown("Boost" + this.playerNumber) && !this.lockBoost)
if (Input.GetButtonDown("Boost" + this.playerNumber) || aiInput[AiInputs.BOOST] > 0 && !this.lockBoost)
{
this.audioSource.clip = this.boostSound;
this.audioSource.pitch = Random.Range(this.pitchModifier.x, this.pitchModifier.y);