- Home /
Preventing a grenade from colliding with its thrower
I am trying to make my player throw a grenade. The problem is that sometimes the grenade collides with the player and hence doesn't take the expected trajectory.
I tried to solve the problem by instantiating the grenade in front of the player by a descent distance (player.transform.position + (player.transform.forward.normalized * 2)). The problem no longer exists but the output is very ugly since the grenade starts apart from the player.
Do you have any suggestions about how to solve this problem or working around it in a more professional way.
Answer by Paparakas · Sep 12, 2013 at 10:35 PM
If the script that instantiates the grenade is attached to the player, you could something along the lines of:
GameObject Grenade = (GameObject)Instantiate(GrenadePrefab,transform.position,transform.rotation);
Physics.IgnoreCollision(this.collider,Grenade.collider);
Thanks a lot. I ended up implementing something similar to your idea.
Answer by meat5000 · Sep 12, 2013 at 03:38 PM
Just Uncheck the Player/Grenade box in the Collision Matrix.
Project Settings -> Physics
Thanks meat5000 for you reply.
Another problem, which I forgot to mention in my question, is that I need the grande to collide with other players who, of course, are in the same layer as $$anonymous$$e. This is a multi-player networked game.