This week my focus was on adding more polish to the NPC opponents. This started with fixing an issue where once their ghost replay function had finished they would often float off into space. This is due to the rigidbody and so the momentum they have would often launch them into a wall and upwards. I fixed this by adjusting the script to turn off the game object once they finished the replay.
if (timeValue >= ghost.timeStamp[ghost.timeStamp.Count - 1])
{
gameObject.SetActive(false);
return;
}
I then wanted to add more personality to the NPC as well as further deepen the player experience. I have implemented what I am calling the Quip system. Essentially the racers will now react to you when they pass/get passed by you by talking to you over the radio. The way I went about this was by first just adding a large trigger collider to each racer.
I then wrote the Quip script for this collider. Since I wanted them to each have three unique dialogue lines I utilised an array to hold the lines. It also uses a global cooldown that is shared between the 3 NPC's to stop dialogue spam.
private static float lastAudioTime = -Mathf.Infinity;
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
if (Time.time - lastAudioTime >= cooldownDuration)
{
if (audioClips.Length > 0)
{
audioSource.clip = audioClips[currentClipIndex];
audioSource.Play();
currentClipIndex = (currentClipIndex + 1) % audioClips.Length;
lastAudioTime = Time.time;
}
As you can see it works by just checking for the Player tag. If entered it first checks if the cooldown is still in effect (currently set to 5 seconds). It then plays the audio clip from the array that each NPC has. It also tracks what element was last played so that it plays the audio from 1 to 3 before looping. This way the player would have to trigger the same NPC 4 times to hear repeated dialouge.
For the dialouge I recoreded myself and my mum's voice to be forever eternalised as NPC. I then used Unity's low and highpass filters on the audio to give it that classic walkie talkie sound.
After this I then worked on the visual componenet for the mechanic. I wanted it to pop up on the players HUD almost like a text message. This is as the HUD is meant to be the dashboard of the ship and so the racers are communicating via the ships comms system. And so I made 3 icons for each racer in photoshop relating to the colours of their ships. Here is yellows as an example:
I then went back to the code and added extra bits to get it to work:
messagebar.SetActive(true);
titleText.text = audioSource.clip.name;
Within the trigger entry I added these two lines allowing for the pop up of the icon and text of the audio file. This works as each audio file is the name of the dialouge said and each racer has their own specific icon assigned to them.
I then added deactivation functions in the Update:
private void Update()
{
if (!audioSource.isPlaying && messagebar.activeSelf)
{
messagebar.SetActive(false);
titleText.text = "";
}
}
I placed these HUD elements under the time within the 'dead space' zone where it doesn't block the player from being able to see important elements of the world. Overall I think this was a great addition to my game and futher polishes and adds personality to the world. Here is a playthrough of the addition:
Opmerkingen