Hello, I’m trying to have a OnTriggerEnter function, but I simply can’t; My cilinder has a Y position of 0.625. Everytime it collides with the ground, it should make a sound, BUT it keeps changing from 0.625 to 0.625000001 back and forward really fast and I have no idea why. (also this is the only axis that keeps changing loads of times). This means it plays the sound everytime the 0.000001 is added.
Help?
The physics has detected a collision with the ground, and because the ground is solid, it unembeds the capsule from it. Then on the next frame, the capsule falls under gravity again and collides with the ground. This is how the code makes you appear to “land” on solid surfaces.
You need to store some internal state so that you can tell the difference between standing on the floor, and landing on the floor after a fall. Luckily you already have it! Try this:
void OnCollisionEnter(Collision collision)
{
if (!isgrounded && collision.gameObject.tag == "Ground")
{
audiosource.PlayOneShot(hitground);
Debug.Log("xd");
}
}