using UnityEngine; public class Rocket : MonoBehaviour { public GameObject player; public Vector3 TargetPosition; public float playerDistance; public Vector3 direction; public Quaternion targetRotation; public float rotationSpeed = 30; public bool isStuck; public float despawnTimer = 10; // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { player = GameObject.Find("Player"); TargetPosition = player.transform.position; } // Update is called once per frame void Update() { if (playerDistance >= 25) { rotationSpeed = 60; } else{ rotationSpeed = 30; } direction = (player.transform.position - transform.position).normalized; targetRotation = Quaternion.LookRotation(direction); transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, 30 * Time.deltaTime); playerDistance = Vector3.Distance(transform.position, player.transform.position); transform.Translate(Vector3.forward * Time.deltaTime * (playerDistance/2+3)); } }