x


Melee attack comblat

I want to make a melee comblat. Now I used the OnControllerColliderHit to work between my character and enemy. But the problem before the script is counting in many time when my character is playing the attack animation. So now I but the cool down timer to prevent it. Finally is ok, but now the problem is the animation between the combo. Sometime the enemy hitted animation will play when I start the combo 2, but sometime will not. What is the problem? Is it the script or animation problem?

below is the script I put

function OnControllerColliderHit (hit : ControllerColliderHit) {
   var myFPSPlayer : CharacterController;
   myFPSPlayer = gameObject.GetComponent(CharacterController);
    if (attackid > 0)
        {
        attackid -= Time.deltaTime;
        }
    if (attackid < 0)
        attackid = 0;
   if (myFPSPlayer)
      Debug.Log ("myFPSPlayer component found");
   if (hit.gameObject.tag == "Enemy" && Input.GetKeyDown("j"))
   {
    if (attackid == 0)
    {
      Debug.Log ("gameObject with tag evil found");
      ApplyDamage(hit.gameObject);
      attackid = coolDown;
    }
   } else {
   Debug.Log (hit.gameObject.name+" don't have tag evil, his tag is "+hit.gameObject.tag);
    }   
}

function ApplyDamage(someObject : GameObject)
{
   var healthScript = someObject.GetComponent("HealthScript");
   if (healthScript != null && animation.IsPlaying("attack1") )
   {
   someObject.animation.CrossFade("hit",0.2);
      healthScript.Health -= 10;
      Debug.Log ("A");
    }
     if (healthScript != null && animation.IsPlaying("attack2") )
   {
   someObject.animation.Play("hit");
      healthScript.Health -= 10;
      Debug.Log ("B");
    }
     if (healthScript != null && animation.IsPlaying("attack3") )
   {
   someObject.animation.Play("hit");
      healthScript.Health -= 10;
      Debug.Log ("C");
    }

if (healthScript != null && animation.IsPlaying("attack4"))
    {
    someObject.animation.CrossFade("die",0.2);
    healthScript.Health -= 10;
    Debug.Log ("D");
    }
}

Also, if I want to work melee comblat, I use colliderhit to do or use physics.raycast to do is better?

Can someone help me

more ▼

asked Apr 09 '11 at 12:39 PM

Pong gravatar image

Pong
0 16 16 18

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

2 answers: sort voted first

See videos of Burg Zerg Arcade, it teaches the basics of this, plus a full RPG, here's the link:

http://www.burgzergarcade.com/hack-slash-rpg-unity3d-game-engine-tutorial

5. Unity3d Tutorial - Melee Combat 1/3

6. Unity3d Tutorial - Melee Combat 2/3

7. Unity3d Tutorial - Melee Combat 3/3

more ▼

answered Apr 09 '11 at 01:32 PM

Unamine gravatar image

Unamine
362 14 17 27

With C# scripts. -.-

Feb 05 at 04:07 PM Lost_C4
(comments are locked)
10|3000 characters needed characters left

I have read the tutorial before... but I dun know how to change it into javascript. Or make the target to be tag"enemy"...

more ▼

answered Apr 10 '11 at 05:16 AM

Pong gravatar image

Pong
0 16 16 18

Making the tag is simple, just go to the Inspector, underneath the object name (top right) says "Untagged", just change that into "Enemy".. :)

Apr 15 '12 at 09:39 PM FizzyBear
(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:

x3339
x1705
x155
x71
x39

asked: Apr 09 '11 at 12:39 PM

Seen: 5363 times

Last Updated: Feb 05 at 04:07 PM