Using Unity 2021.3.20f1 and FMOD 2.02.13.
This is a weird one, so bear with me as I try my best to explain the situation.
The current game I’m working on is a haunted corn maze, so it’s mostly a flat plane without any jumping or falling. However, there are sporadically-placed bales of hay throughout the maze that the player can climb upon. I’m trying to have minimal controls for this game since I’d like to eventually port it to smartphone apps, so rather than having a climb mechanic, I just increased the player’s step threshold to match the height of the hay bales, they will simply just “step up” on top of the bale.
Now, what I’m trying to add to the game is that when they get down off of the bale, it plays a landing footstep sound. In other games, I did this by detecting in the script if the player was ungrounded in the previous frame, is now grounded in the current frame, and if so then the landing sound should be triggered. This doesn’t work for this example, however, since the step threshold was increased, it’s not reading the player as being ungrounded, just taking a step down.
The way I figured out around this was to add a trigger collider to the hay bale, and when the player exits the collider, that is what triggers the landing sound effect.
Easy enough - but here is where it gets weird.
It only works on two of the sixteen bales of hay - even though the bales are all prefabs that have not been altered, so they all have the same 3d dimensions. I also have them all placed at the same Y coordinate, just the X and Z coordinates differ.
According to the Unity console, the events are being triggered in the script on all of the bales of hay, but for some reason the sound is only playing when stepping off of these two bales - which I have gone over again and again and confirmed that there is nothing different from these bales and the others, aside from the X and Z coordinates.
Here’s the Trigger Exit script:
void OnTriggerExit(Collider col)
{
if (col.gameObject.tag == "HayStack")
{
StartCoroutine(LandingSoundDelay());
print("Landing: On Trigger Exit");
}
}
IEnumerator LandingSoundDelay()
{
yield return new WaitForSeconds(1);
firstPersonController.PlayLandingSound();
}
And here’s the PlayLandingSound() function from the First Person Controller Script:
public void PlayLandingSound()
{
if (Physics.Raycast(playerCamera.transform.position, Vector3.down, out RaycastHit hit, 5, ~playerLayer))
{
switch (hit.collider.tag)
{
case "Footsteps/Grass":
FMODUnity.RuntimeManager.PlayOneShot("event:/Player/Footsteps/Landing/GrassLand");
break;
case "Footsteps/Dirt":
FMODUnity.RuntimeManager.PlayOneShot("event:/Player/Footsteps/Landing/DirtLand");
break;
case "Footsteps/Leaves":
FMODUnity.RuntimeManager.PlayOneShot("event:/Player/Footsteps/Landing/LeavesLand");
break;
case "Footsteps/Mud":
FMODUnity.RuntimeManager.PlayOneShot("event:/Player/Footsteps/Landing/MudLand");
break;
}
NextStep = StepCycle + .5f;
print("Landing: Player Landed on " + hit.collider.tag);
}
}
Attaching below screenshots of the Unity Console Log - self explanatory, but “Landing - On Trigger Enter” is when the player enters the trigger zone, “On Trigger Exit” is when the player leaves the trigger zone, and “Landing: Player Landed On [Ground Type]” indicates that the landing sound function was triggered to play the FMOD event which correlates with the player’s footsteps - you may notice the last function occurs a second after the exit is triggered, that’s because for testing purposes I triggered the function via a Coroutine with a 1 second delay, but this will obviously not be the case in the final product.
Also attached below are screenshots of each of the FMOD events: one for landing on dirt, one for grass, one for leaves, and one for mud. Also including screenshots of the hay bales in Unity, with their inspector details - bales 3 and 4 are the two that work properly, the rest do not work. I turned the volume nobs all the way up for testing, to ensure that I wasn’t confusing the landing sound with a regular footstep.
Any suggestions would be greatly appreciated!