Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Xero Vortex · Feb 14, 2014 at 12:36 AM · 2dcollisioncollision detectionunity 4.3

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!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Xero Vortex · Feb 16, 2014 at 12:18 AM 0
Share

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.

avatar image CatKillen · Feb 16, 2014 at 12:40 AM 0
Share

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.

avatar image Xero Vortex · Feb 17, 2014 at 02:11 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges