Really confusing float question
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?
Your code shouldn't care about the difference between 0.625 and 0.625000001. The problem is not in that $$anonymous$$or variation, the problem is in how your code is dealing with it.
Post the code for further input.
@jgodfrey I'm posting a pastebin, the code is too long.
$$anonymous$$y ontrigger part is at the bottom, however maybe something from the rest may be relevant
Also do you know how I can stop the charactercontroller from always putting me 0.1 units above the air? $$anonymous$$y capsule is in 1 Y-unit in the air and the controller has the height 1.
Answer by Winterblood · May 02, 2016 at 12:24 AM
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");
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612075942im_/https://answers.unity.com/themes/thub/images/avi.jpg)