- Home /
How to stop my sword from hitting myself
I am trying to get my player to swing his sword and hit other players in a network game. Currently my sword during idle and swinging animations collides with my character and begins to take away his health.
I can't change my tag to "Player" and everyone as "Enemy" because all the players in the game will be real players.
How can I find out if my collider is attacking myself and stop it before it does?
I've read about raycast and ignoring collisions but I'm not firing a bullet.
Answer by LaneFox · Jun 30, 2015 at 12:50 PM
Physics.IgnoreCollision(theCharacterObj.GetComponent<Collider>(), theWeaponObj.GetComponent<Collider>());
You can use this to ignore collisions between two colliders. You'll want to get a reference to the character collider and the collider which the weapon represents and specify them both in this method.
This is better than comparing them at each collision because that could happen very frequently, leading to needless performance drops.
That's great, thank you so much, I'll give it a try shortly.
Answer by Richardm1985 · Jun 30, 2015 at 10:41 AM
Solved.
Looks like I need to check with this code:
collider.transform.root;
Your answer
Follow this Question
Related Questions
Best collision detection method? 2 Answers
WheelCollider - I don't have a circle of Collider 1 Answer
Unity 5 physics change from Unity 4 help! 2 Answers