sorry for that kind of stupid questions… but i get a headache every time i try to fix this problem… the problem is … i made a GameObject and i told him to move to the target that the player have choosed… but when it moves to the target it keeps rotating crazy, this is the script that i used
using UnityEngine;
using System.Collections;
public class PickedLocust : MonoBehaviour
{
public static PickedLocust Instance;
public CharacterController characterController;
public float time;
public Transform Player;
public Transform startPos;
public Transform target;
private int moveSpeed = 15;
Vector3 moveVector { get; set; }
void Awake()
{
Instance = this;
characterController = GetComponent("CharacterController") as CharacterController;
}
public void Update()
{
characterController.Move(moveVector * Time.deltaTime * moveSpeed);
if (Leader.Instance.target != null)
{
target = Leader.Instance.target;
}
if (target)
{
transform.LookAt(target);
moveVector = transform.TransformDirection(Vector3.forward);
}
else if (!target)
{
moveVector = new Vector3(0, 0, 0);
target = startPos;
}
}
void OnTriggerStay(Collider OtherObjects)
{
Food FoodScript = OtherObjects.GetComponent("Food") as Food;
float health = FoodScript.Health; ;
FoodScript.Health--;
}
}
and i have tried to make the gameObject move only if the distance between it and the target is greater then 2 , but it didn't work , the gameObject keebs moving up, down, left, and right
– Ziad