x


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.

more ▼

asked Jan 22, 2012 at 03:22 AM

clanssd gravatar image

clanssd
1 3 2 2

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Well, I am doing a simple 2.5d game too. In my game I use something like:

  1. Create a empty object;
  2. Attach in this object a script with
 only a Gizmos function;
  1. Put a collider in this object;
  2. 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.

more ▼

answered Jan 22, 2012 at 01:41 PM

Kaze_Senshi gravatar image

Kaze_Senshi
173 41 36 42

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?

Jan 24, 2012 at 02:13 AM clanssd

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}

Jan 24, 2012 at 03:18 AM Kaze_Senshi
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x7063
x4374
x3256
x1199

asked: Jan 22, 2012 at 03:22 AM

Seen: 2201 times

Last Updated: Jan 24, 2012 at 03:18 AM