So im using a script
if (rigid.velocity.z == 0 && JumpScript.grounded == true)
{
audio1.SetActive(true);
}
else if (rigid.velocity.z == 0)
{
audio1.SetActive(false);
}
but even if the velocity is 0 and im not moving atall the sound won’t stop i don’t know what im doing wrong i am a bit tired might be it or im just bad :p, i would appreciate some help if someone knows how to solve this :), i’ve tried to use this method on a jump script but never got it working aswell so i stopped trying with that version but this is the best idea i can come up with for this atm.
You can set the .isKinematic property (on your Rigidbody) to false and it will stop acting like a physics object, if that is what you want.
If isKinematic is false it will act like a “normal” physics object. If isKinematic is true it stops being effected by other physics objects and can be controlled by translating the transform or using animations. Also when it is kinematic it can push other non-kinematic objects.
Testing equality on a float you did not set yourself can be tricky. Perhaps you should use approximation instead like this.
bool isStationary = Mathf.Approximately(rigid.velocity.z, 0f);
if (!audio1.activeInHierarchy && isStationary && JumpScript.grounded == true)
{
audio1.SetActive(true);
}
else if (audio1.activeInHierarchy && isStationary)
{
audio1.SetActive(false);
}
1 Like