- Home /
Question by
jgratrix · Dec 31, 2015 at 09:39 AM ·
quaternionspacespace shooterspaceship
unity3d quaternion slerp is off target
so ive made a simple ai path follower for my small fighters however now with this bigger ship i made rather than it looking at the next path point its facing down here is my code:
public class MediumAI : MonoBehaviour
{
public Transform[] path;
public float speed = 4f;
public float reachDist = 2f;
public int currentPoint = 0;
Rigidbody rb;
// Use this for initialization
void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
Quaternion neededRotation = Quaternion.LookRotation(transform.position - path[currentPoint].position);
transform.rotation = Quaternion.Slerp(transform.rotation, neededRotation, Time.deltaTime * 0.5f);
float dist = Vector3.Distance(path[currentPoint].position, transform.position);
//transform.position = Vector3.MoveTowards(transform.position,path[currentPoint].position,Time.deltaTime * speed);
rb.AddForce(transform.forward * -7F);
if (dist <= reachDist)
{
currentPoint++;
}
if (currentPoint >= path.Length)
{
currentPoint = 0;
}
}
}
Comment