Sound when ball hits and not when rolling?

Hello,

I have a 2d soccer ball. You can kick it.
Now, I want to play a sound, when the ball falls down and hits the ground. One or more times. But I don’t want to play a sound, when the ball is rolling.

How can I do that? I searched a little bit. Is this the answer?:
rigidbody.velocity.magnitude > 0.5

And is there a way to make the sound higher or lower depending on the hit? For what I must search for?

Use this built-in function to run code when the ball collides with something.
You can use the relative velocity to play a sound when needed. ;o

Hmm, but what is when the ball touching the ground and rolling. Collider.OnCollisionEnter does not stop. It’s always collision enter?

What do you mean, it gets called when you physically iteract with another object.

can’t really know what exactly u are doing and how you did it.
but I assume that what you want to do is only play hit sound when ball hit the ground, not when on the ground.

So you can set up this way. just need a simple boolean toggle to control:

public AudioClip hitclip;
bool hitGround;


void PlayHitSound(){
AudioSource.PlayAtPoint(hitclip,transform.position);
}

void OnCollisionEnter2D(Collision2d other){

// you may want to add a condition here
// if other.tag == "ground";

if(!hitGround){
PlayHitSound();

hitGround = true;
}
}

void OnCollisionExit2D(Collision2d other){
hitGround = false;
}