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

Kind of Lag in movement

$
0
0
Hello there , I have a guarding script in which enemy patrol around specific area and I have provided waypoints to the gameobject but the problem is that it movies like the game is lagging . Its movement is not smooth . I have made a coroutine and did "Startcoroutine" in START() function . Following is my code > IEnumerator FollowWayPoint(Vector3[] waypoints) > {> //set the enemy position to first wayPoint> transform.position = waypoints[0]; int targetPointIndex = 1; Vector3 targetPoint = waypoints[targetPointIndex]; while (true) { // Make the enemy move towards the target Point. transform.position = Vector3.MoveTowards(transform.position, targetPoint, speed * Time.deltaTime); // When Enemy is on the target Point . if(transform.position == targetPoint) { // Increase the targetPointIndex by 1. targetPointIndex = (targetPointIndex + 1) % waypoints.Length; } targetPoint = waypoints[targetPointIndex]; yield return new WaitForSeconds(waitTime); } }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



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