How to Lock rotation for few seconds only when every time the object rotates 180 degree?
Hi guys! Actually, I have an AI for fishes swimmer around in an area. Everything is working fine here. However, after I created some bubbles and when they collided to some fishes, some of them start rotating itself forever. I researched and trying to solve it for a long time, but I really can't fix it.
Everything is fine without the bubble, but I really need that bubble. So, I'm thinking maybe just let the bugged fish stop rotating for few second will solve the problem, but I really have no idea how to do that.
You can use a coroutine to stop them for a few seconds or do you want the fish to not be affected by collision with the bubbles? @Supercell0w0
I think I want them not be affected by collision.
But the code isn't working
void OnCollisionEnter(Collision collision) { if (collision.gameObject.tag == "Bubble") { Physics.IgnoreCollision(Bubble.collider, collider); } }
You can add them to different layers and disable the physics. https://answers.unity.com/questions/686915/how-do-i-get-some-objects-to-ignore-collision-with.html
Answer by RealFolk · Jan 27, 2021 at 01:14 PM
Without seeing your code i can't say. You need to get the actual collider component on the game object. BoxCollider, or SphereCollider, etc..
Physics.IgnoreCollision(this.gameobject.GetComponent<Collider>(), collision.gameObject.GetComponent<Collider>());