I have an enemy character in my game that has a very long tongue that needs to roll in and out of the character’s mouth whenever the main player is in range. This tongue needs to give damage to the main player, and when the tongue hits the main player the tongue needs to return into the enemy’s mouth.
So far all of my other enemy characters remain the same size, and I just have a box collider on them to trigger damage to the main player. I don’t think the box collider will work for this new enemy character that has the tongue that rolls in and out because if I make the box the size of the character when the tongue is in the mouth then the tongue rolling out won’t trigger any damage to the main player – And if I make the box large enough to accommodate the long tongue, then the box will be too large when the tongue is inside of the mouth still.
An easy way, not the best way, to do this would be just prebake colliders, by just having multiple collider components on the object or seperate hitbox objects, using some Unity collider type like their polygon collider. Then you can activate and deactivate the ones on the sequence to match the tongue.
It is just to complex to explain over a forum. The point is it costs allot of memory and allot of performance in comparison to other methods that you would just have to find on your own within the bounds of your project; if you don’t need thousands of them running simultaneously you should be fine.
There are various ways I could see doing this.
-As already mentioned, just have multiple colliders that you turn on and off as needed.
-Fake it by having a separate object situated probably at the front of the tongue which moves with the front of the tongue and has a static collider (a lot of games do it this way as you’ll often notice things don’t collide behind the tip, only at the tip).
-Dynamically change the size of the collider in script. You can alter the size and positioning of colliders in script, and this is probably the most collision correct way to do the job. Getting the positions right will either require you to measure frame by frame how big the collider should be and hard code that in, or do some math based on the sprite size if that is possible (you’ll more likely be stuck with the former honestly as it is pretty rare for a sprite sheet to change size exactly for each frame). Essentially this is similar to the first option just with only one object and more code required.