0
\$\begingroup\$

A 2D game and a bird's eye view of the character. This character, who has a knife in his hand, swings the knife by waving his arm, just at this time, I look at "polygon collider2d" from the unity "scene" tab and it does not follow the character's arm or knife. Therefore, the character's knife, arm go into the wall or don't damage the enemy. Because the polygon collider2d is only scaled when the character is in the "idle" state.

My question is right here, do I need to add polygon collider2d separately for each frame of my attack animation and make them active/passive while the animation is playing?

Doesn't doing this degrade performance? I couldn't find an alternative solution.

Solution Edit : The only way to solve this problem is to keep our sprites in separate pieces and prepare the animations we want from unity's own animation window.

Note: In the classical method, we can create animation by dragging and dropping the ready frames to our object, but in this case the collider will not follow the object.

\$\endgroup\$
7
  • \$\begingroup\$ "it does not follow the character's arm or knife." It does if you tell it to. I presume you tried to attach the collider to the game object representing the knife, or to its own object that you've animated to follow the knife's movement in the attack animation? Walk us through how you set up your character and animation, and we can help you find what you missed. \$\endgroup\$
    – DMGregory
    Sep 13, 2021 at 17:21
  • \$\begingroup\$ Let me explain with an example. The sword is not an external gameobject. imgur.com/EoloVtz imgur.com/fufCPq6 \$\endgroup\$
    – gunza
    Sep 13, 2021 at 22:28
  • \$\begingroup\$ So then you make an external game object, no? You are not limited to using a single object per character, even if the sprite is only displayed on one object. \$\endgroup\$
    – DMGregory
    Sep 13, 2021 at 23:02
  • \$\begingroup\$ But this won't solve my problem. Because the sword will move again and while it moves, it will go out of the collider just like in the picture and will not be able to damage the enemy object, right? The main problem is that the collider pattern does not automatically wrap around objects that change shape during gameplay. \$\endgroup\$
    – gunza
    Sep 13, 2021 at 23:09
  • \$\begingroup\$ No, because you add an animation that moves the object with the sword's collider in sync with the sprite animation. \$\endgroup\$
    – DMGregory
    Sep 13, 2021 at 23:10

1 Answer 1

0
\$\begingroup\$

I think what you are trying to do is make melee combat for your player. You should look in physics2d section of overlapping circles and stuff. But you can also look up brackeys tutorial for melee combat which explain everything perfectly. https://www.youtube.com/watch?v=sPiVz1k-fEs

\$\endgroup\$
1
  • \$\begingroup\$ This answer would be better if it explained how to apply "overlapping circles and stuff" to solving the melee combat problem. \$\endgroup\$
    – DMGregory
    Sep 13, 2021 at 17:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .