using UnityEngine;
using System.Collections;
public class WaypointsMover : MonoBehaviour {
public float rotateSpeed = 2.0f;
private bool rotating;
void Update() {
StartCoroutine(TurnTowards(-transform.forward));
}
IEnumerator TurnTowards(Vector3 lookAtTarget) {
if(rotating == false) {
Quaternion newRotation = Quaternion.LookRotation(lookAtTarget - transform.position);
newRotation.x = 0;
newRotation.z = 0;
for (float u = 0.0f; u <= 10.0f; u += Time.deltaTime * rotateSpeed) {
rotating = true;
transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, u);
yield return null;
}
rotating = false;
}
}
// Use this for initialization
void Start () {
}
}
No matter if i change the value of rotateSpeed to 10.0f or to 20.0f the enemy will get to one side will walk some on place and then will turn and walk to the other side. How can i make that the enemy will turn right away when getting to the side ?
Why the enemies positioned there on the building roof while in the scene i position them in another places at all ?
How do i set waypoints ? I can't find in the code way points. I know that in the for loop it was in the original:
for (float u = 0.0f; u <= 1.0f; u += Time.deltaTime * rotateSpeed) {
I changed it to 10.0f instead of 1.0f so now they are walking longer way on the roof. But if i want to make that they will go between two spheres i have ?
This is a screenshot of the scene the building on the right where they walk on it's roof when running the game. The two enemies(Guards) on the left on the right it's the Main Player. The camera i set it to follow the first Guard.
I also noticed there is not space between them so they collide each other or disturb each other to walk. Where or how can i set more space between them so each one will go on it's own path ?
This is a short video clip i recorded showing how they are walking and where they are walking: