Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

How can I make my enemy stay on the ground and collide with other objects?

$
0
0
In my script the enemy chases the player until it is close enough to attack, but they enemy doesn't stay on the ground and flies through walls. How can I make it obey gravity? here's my code: using UnityEngine; using System.Collections; using UnityEngine.UI; public class EnemyChase : MonoBehaviour { public Transform Player; public int MoveSpeed = 4; public int MinDist = 5; public int MaxDist = 10; public Slider healthBarSlider; bool attack; void Update() { //squares up transform.LookAt(Player); //chases player if (Vector3.Distance (transform.position, Player.position) <= MaxDist) { transform.position += transform.forward * MoveSpeed * Time.deltaTime; //stops doing damage attack = false; Debug.Log ("get over here and fight like a man!"); //stops and attacks when close enough to player if(Vector3.Distance(transform.position,Player.position) <= MinDist) { Debug.Log ("PEWEWPEWEPWEWPEPWP"); //starts doing damage attack = true; } } //applies damage to player if (attack) { healthBarSlider.value -= 0.005f; } else if (healthBarSlider.value == 0) { //die } else { healthBarSlider.value += 0.0f; } } }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



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