I want to create an enemy for the roll-a-ball tutorial that follows the player and has acceleration.
here's the current script:
using UnityEngine;
using System.Collections;
public class Homing : MonoBehaviour {
public Transform target;
public float force = 10f;
void Update () {
Vector3 targetDelta = target.position - transform.position;
float angleDiff = Vector3.Angle(transform.forward, targetDelta);
Vector3 cross = Vector3.Cross(transform.forward, targetDelta);
GetComponent().AddTorque(cross * angleDiff * force);
}
}
↧