- Home /
How Can I Detect Collision For Part of a Sprite?
I'm looking to create a 2D game (using the new 2D tools) where characters can swing swords and I want to be able to detect if something collided with just the sword, and not the rest of the sprite.
I have not made the character assets yet. The simplest method seems to be making the sword a separate sprite, but I would like to make the character and sword in the same sprite.
This seems like a similar problem for sprite-based 2D fighting games: when a character punches we would want to check collision with the fist, not the whole sprite, to determine if an attack has landed on the opponent. How can I do something similar?
Disclaimer: I'm brand new to Unity and newish to game dev.
Thank you!
Answer by KrisJulio · Feb 14, 2014 at 04:47 AM
My way maybe I add invisible gameobject in front of my character with the range of the sword when attacking. And at first this must be SetActive(false) and whenever the player attack you must set it to true. Add also a collider there to check if it hits with the enemy. Just my two cents
Hm, that seems like it wouldn't work well for a slashing motion since a hit would be registered from a collision anywhere in the gameobject.
Attaching the invisible collision box would make it act like a hitbox, and is the basis of fighting games. You'd have to animate it to move with the animation.
If this is really the way that I'd have to go, it might indeed be simpler to just have the sword separate from the character.
I guess I felt like I was missing something and that there was a better solution.
Your answer
![](https://koobas.hobune.stream/wayback/20220613133435im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Child Collides If Its The Parents Collider 0 Answers
Childs Collision Calls Parents OnTriggerEnter2D() 0 Answers
Objects don't collide 1 Answer
Collision & 2D 2 Answers
isTouching() with multiple colliders 0 Answers