Quantcast
Channel: Questions in topic: "follow"
Viewing all articles
Browse latest Browse all 536

C # script the enemy chases the player.

$
0
0
Hello everyone. I have this script that does not work for the enemy. When the player approaches the enemy, it is not pursued. The enemy remains still in place. What could be the problem? Script of the enemy: using UnityEngine; using System.Collections; public class EnemyInseguePlayer : MonoBehaviour { public Transform player; public float playerDistance; public float playerXAxis; public float moveSpeed; // Use this for initialization void Start () { } // Update is called once per frame void Update () { playerDistance = Vector3.Distance (player.position, transform.position); if(playerDistance < 15f) { LookAtPlayer (); } if(playerDistance < 18f) { chase (); } } void LookAtPlayer() { Vector2 playerXAxis; playerXAxis = new Vector2(player.position.x, player.position.y); } void chase() { transform.Translate (Vector3.forward * moveSpeed * Time.deltaTime); } }

Viewing all articles
Browse latest Browse all 536

Trending Articles



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