Basically im trying to make a physics based guided missile script, so far i have this:
public Transform target;
public float force = 0.5f;
private bool ifTarget = false;
public void SetTarget(Transform helTarg){
target = helTarg;
ifTarget = true;
}
void Update () {
if(ifTarget){
rigidbody.AddForce(transform.up * 100);
Vector3 targetDelta = target.position - transform.position;
//get the angle between transform.forward and target delta
float angleDiff = Vector3.Angle(transform.forward, targetDelta);
// get its cross product, which is the axis of rotation to
// get from one vector to the other
Vector3 cross = Vector3.Cross(transform.forward, targetDelta);
// apply torque along that axis according to the magnitude of the angle.
rigidbody.AddTorque(cross * angleDiff * force);
}
}
But this only causes weird behaviour with the missile, as seen here:
{{title}} (Target a tank with Tab and Press F for HellFire missiles, then click)
How would you go about a proper or a simple way to do this type of thing, also how would you make it go towards a target without using addForce, as that increases the speed at the same time.