- Home /
OTriggerEnter and Gravity is not Working Together
i have a wall.When i enable gravity then the throwing ball bounced to the wall and come back but in this case it doesn't execute OnTriggerEnter. when i checked both gravity and trigger the ball passes through the wall.my code is nothing special.that's why i didn't it write it here.please help me solving this problem
i want to bounce on the wall and also want to add a sound on bounce.thats why i am looking for trigger event.if you have other way to do so please help me.
Answer by Owen-Reynolds · Sep 19, 2012 at 04:54 PM
[minor edit] If you want it to bounce off the wall, you can have that "trigger" a sound, but have to name it `OnCollisionEnter` instead of `OnTriggerEnter`. See the reference manual for the magic words you need (Search for Unity OnCollisionEnter. The example even plays a sound.)
For example, suppose you have an OnCollision and an OnTrigger in the same script. Unity will run one on a hit, depending whether isTrigger is checked. The other one is always sort of in reserve, in case isTrigger gets flipped.
tnx onCollisionEnter works.But i have a problem on audio source.it is giving me a error of audio source while everything is ok.
Separate issue. Try to play a sound in Start, or in Update on a button click, and work it out. Once you have "play a sound" working, you can move the code into a fancy OnCollision, or wherever.
Your answer
![](https://koobas.hobune.stream/wayback/20220613081230im_/https://answers.unity.com/themes/thub/images/avi.jpg)