- Home /
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
Answer by Unamine · Apr 09, 2011 at 01:32 PM
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
I have read the tutorial before... but I dun know how to change it into javascript. Or make the target to be tag"enemy"...
$$anonymous$$aking the tag is simple, just go to the Inspector, underneath the object name (top right) says "Untagged", just change that into "Enemy".. :)
Your answer
Follow this Question
Related Questions
I'm still having Trouble with this AI script 2 Answers
This melee damage detector won't work... 1 Answer
Melee Combat 1 Answer
Ai Zombie Melee Attack script. 5 Answers
character area attack problem 1 Answer