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

Sword Combat System: Detect if player in range

$
0
0
Ok, guys, I've been Googling, testing, and experimenting for the past 2 hours. I have a first person character with a sword. I need him to attack the enemies and give them damage. I'm hitting a hiccup in that I can't figure out how to detect if the enemy is in range. I think this is how I want the system to work: I have a box collider in front of my main character. I want the box to check every frame whether or not an enemy is touching the box. If there is an object with the tag "enemy" in the box, I want a boolean variable to be true, and if there is no enemy in the box, then I want the variable to be false. Right now, I can get the variable to be true when the box collides with the enemy, but I can't seem to get it to change to false. var enemyInRange : boolean = false; function OnTriggerEnter (other : Collider) { if(other.gameObject.tag == "enemy") { enemyInRange = true; } } function OnTriggerExit (other : Collider) { if(other.gameObject.tag == "enemy") { enemyInRange = false; } } function Update() { // Tells me what the value of the variable is, so that I can see if it changes Debug.Log(enemyInRange); } Thanks for the help!!!

Viewing all articles
Browse latest Browse all 201

Trending Articles



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