Melee And Impact

I currently have a working (but extremely simple) Melee Combat system. All works ( for the most part ) as far as collision goes. The problem however, is adding realistic impact so that the player has time to hit the enemy several times before the enemy can reach distance for attacking.

Things to know:
-Both Objects are Ragdolls .

The problem:
-Sometimes, depending on the type of attack, the ninjas ‘sword’ does not collide with the enemy. I know this has everything to do with the animations coords. But how do I ensure I always get a hit, as well as a nice knockback factor. On about three of my animations, the characters alignment causes the collider to always be in contact with the targeted collider, and that’s not what I want :\

Here is a photo of the colliders seperated:
alt text

And here is them colliding:

alt text

And here are my scripts:

//Sword Collision
function OnTriggerEnter ( collision : Collider ){
	if ( !Controller.Player.Attacking || collision.tag != "Zombie")
	//Debug.LogWarning("Collided with" + collision.collider.tag);
	if ( collision.tag == "Zombie" )
		Controller.Player.Kombat.HitCount += 1 ;
		Controller.Player.Kombat.HitCountCooler = Controller.Player.Kombat.HitCountCoolerMax ; 
		if ( Controller.Player.Kombat.HitCount > 4 ){
			Instantiate( Resources.Load ( "Detonator-Crazysparks" ), transform.position, Quaternion.identity ) ;
			Controller.Player.Kombat.HitCount = 0 ;
		Debug.LogWarning ( "Collision33?" );
		EnemyMotor = collision.GetComponent ( ZombieMotor ) ;
		EnemyMotor.SendMessage ( "DamageFactor", 300 ) ;
		collision.GetComponent( AddForce ).addForce ( -Vector3.forward, 10 );
		Instantiate( Resources.Load ( "Assets/Standard Assets/Detonator/Prefab Examples/Detonator-Crazysparks.prefab" ), transform.position, Quaternion.identity ) ;

//Zombie Damage Factor
function DamageFactor ( damage : float )
	if ( ZombieIntelligence.Zombie.Kombat.Health < 0 ){
		Kill ( ) ;
		var myForce : AddForce ;
		myForce = GetComponent ( AddForce ) ;
		myForce.addImpact ( Vector3.forward, 10 ) ;
	ZombieIntelligence.Zombie.Kombat.Health -= damage * ( ZombieIntelligence.Zombie.Kombat.Defense / 100 );

Any help is greatly apreaciated! Thanks in Advance!


are you saying when at rest essentially its colliding and thats the problem?

assuming making the collider smaller wont fix it what your going to want to do is ignore collision UNTIL you’ve decided your at a point in your animation where your like ok i’d now like to test for collision.

lets say for example right now you have an attack animation that first draws the sword back then swings it forward to attack.

Split that into 2 animations. Lets say DrawBack and OverHandSlice.

Start out by default having collision detection on the sword disabled. Admittedly this will allow it to go through wall and stuff but again yea that happens in real games, in real games if your character can get right up on another character or a wall your weapons will stick through some.

on mouse button 1 Call DrawBack now at the end of DrawBack do two things
first enable collision detection now, then call OverHandSlice. Now at the end of overhand slice disable collision detection again. If they draw back it’ll reenable and you can go at it again.

Post comments if you need more help or mark if answered.

As I said i’m only fairly certain your problem was collision during “rest” if its different comment and i’ll help.