Problems with Colliders
Reported By: David Tarnowski
September 22, 2023
THE PROBLEM
This week I encountered an issue where the collider on the player's sword was active at all times, even when not attacking. This meant the sword could damage enemies just by walking past them instead of requiring a proper attack animation. Having an perpetually active collider broke our combat logic and allowed exploiting damage without attacks. It also looked visually odd to see enemies reacting to an inactive weapon.
The root cause was that the sword game object spawns at runtime, so I could not directly set the collider enabled state since it did not yet exist in the editor. I needed a way to toggle the collider from code based on attack animations.
THE SOLUTION
To fix this, I created an animation event that triggers right when the sword swing begins. The event calls a RightWeaponColliderEnable() function I added to the sword script, passing true to activate the collider.
I also added an event that triggers when the swing finishes, calling RightWeaponColliderDisable() to disable damage. This properly turns the collider on and off based on attack animation states.
The challenge was the sword is a child of the character's hand which is a child of the arm, which required recursively traversing the hierarchy to find the Sword component. With the animation events and using FindChild() method, I can now enable and disable the collider in sync with attack animations.
This solved the issue of the sword incorrectly damaging enemies and fixed the odd visuals of enemies reacting to nothing. Attacks now feel satisfying as the collider correctly activates on swing animations.
Get Psyche
Psyche
Welcome to your next great souls-like adventure!
Status | In development |
Author | Sad Ogre Studios |
Genre | Role Playing, Adventure |
Tags | Atmospheric, Fantasy, Indie, mind-bending, psyche, Sci-fi, Singleplayer, Souls-like, Third Person |
More posts
- Problem: Harder Isn't Always More FunDec 14, 2023
- How to make the controller feel more responsiveDec 14, 2023
- ModelMayhem: A Programmer's TaleDec 08, 2023
- Problem: Face Your FearsDec 03, 2023
- Time to show our real main characterDec 01, 2023
- Problems: melee combat system is too boringNov 24, 2023
- Problem: Frames Win Games?Nov 17, 2023
- Problem with camera transitionNov 16, 2023
- Combo Attack systemNov 11, 2023
- Problems with code reusabilityNov 03, 2023
Leave a comment
Log in with itch.io to leave a comment.