This is what I did for missiles following an enemy.
// Get the direction we need to rotate towards
rotation = Quaternion.LookRotation(target.position - this.transform.position);
// Rotate towards the target
transform.rotation = Quaternion.RotateTowards(transform.rotation, rotation, rotateSpeed * Time.deltaTime);
This is to move:
// Move towards the target
rigidbody.AddForce(acceleration * transform.forward, ForceMode.Acceleration);
// Don't go above maxSpeed
rigidbody.velocity = Vector3.ClampMagnitude(rigidbody.velocity, maxSpeed);
Hope it helps!
↧