Quantcast
Channel: Questions in topic: "melee"
Viewing all articles
Browse latest Browse all 201

How can I attach a colldier that moves with the enemies sword in an attack animation?

$
0
0
This is the current code I have on all of my enemies, it checks to see if the character is within range, and then it plays the attack animation and removes health from the player. I want to have it set up so a coliider is on the sword of the enemy, that way it only reduces damage when you are actually hit by the sword, not just being close enough How would I implement this? void Update () { if (spartanPt < 0 && sAlive == true) { gameObject.transform.parent.gameObject.GetComponent().Play("die"); sAlive = false; Destroy(gameObject.transform.parent.gameObject.GetComponent ()); } else if (sAlive == true) { Vector3 heading = GameObject.FindGameObjectWithTag ("mazeDude").transform.position - transform.position; float distance = heading.magnitude; Vector3 direction = heading / distance; if (heading.sqrMagnitude < maxRange * maxRange) { gameObject.transform.parent.gameObject.GetComponent ().Play ("attack"); GameObject.FindGameObjectWithTag ("sword").GetComponent ().healthPt -= 3; } }

Viewing all articles
Browse latest Browse all 201

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>