- Home /
Collisions with an animated character
Hello there,
I apologize if this is a common question. I tried my best to search through existing questions for a good amount of time but couldn't find anything relevant.
I'm working on a 2.5D Castlevania style game. I've been trying to figure out the best way to implement attacks for the character and enemies without physically moving them forward to force a collision. They are mostly punch/kick animations with a limited number of attacks with melee weapons. The player character and enemies both use Character Controller components.
The only idea I've come up with so far is attaching colliders to the hand and foot joints of the models so that when they plays their animations, the colliders are driven forward through them, but this would require a separate script for a GameObject attached to the hands/feet correct (I'm working in C#)? Is this a sensible solution to this game mechanic? Is it possible to have a mesh collider that moves along with animations? I've tried to do this, but the meshes all seem to be stuck in the T-pose.
I ask because I followed the Lerpz 2D tutorial's system for handling footsteps sounds and particles, and I thought it was great while setting up my intro stage but it's becoming rather tedious to have to add in the scripts for every surface, even while using prefabs because the levels I'm designing after that are rather large and have a lot of unique surfaces.
Thanks for reading and I hope someone can suggest a more efficient method.
Answer by Kaze_Senshi · Jan 22, 2012 at 01:41 PM
Well, I am doing a simple 2.5d game too. In my game I use something like:
Create a empty object;
Attach in this object a script with only a Gizmos function;
Put a collider in this object;
Attach the empty object in some enemy;
So the empty object works like a "hurting area", my character just need to have a "if" inside the collider detection.
function OnTriggerEnter (other : Collider)
{
...
var enemyDamageDetector : EnemyDamageDetector = other.gameObject.GetComponent( EnemyDamageDetector );
if( enemyDamageDetector )
{
SendMessage ( "DidHit", SendMessageOptions.DontRequireReceiver );
return;
}
}
This way, it is just put the script where I want. You don't need to make the script more, only reuse it. I think that you can jump the step 1 and put the script in the joint of the knuckles of your character or wharever.
Thanks for the answer. How do you prevent accidental collisions? When my character runs, her hands stick out pretty far and I don't want that to cause enemies to get damaged just by running into them. Just turn off the collider component when the character isn't attacking?
Oh yeah, In my game you can damage enemies doing a "piercing dash". So when I press the button "fire2", I turn on one boolean "isDashing" and when its time ends, I turn it off. The if code becomes something like:
(...) if( enemyDamageDetector && player.isDashing() ) {Hurt enemy code}
In your case, I think you will want to damage enemies only when some specific animation is playing. I think is something like:
(...) if( enemyDamageDetector && (animation["falconpunch"].enabled == true)) ) {Hurt enemy code}
Your answer
Follow this Question
Related Questions
How to have other (any) Objects smoothly push a Character Controller? 1 Answer
Export Animations From Unity3D into Blender? 1 Answer
How to stop an animation on collision 0 Answers
Rigidbody: how to get collisions for the current frame ? 0 Answers
Physics goes crazy when rigidbody collides with moving character controller 0 Answers