Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class HomingMissleScript : MonoBehaviour
- {
- public Transform target;
- public float speed;
- public Rigidbody rb;
- public float rotateSpeed;
- public void FixedUpdate()
- {
- Vector3 direction this.target.position - this.rb.position;
- this.direction.Normalize();
- float rotateAmount = Vector3.Cross(direction, transform.up).z;
- this.rb.angularVelocity = -rotateAmount * rotateSpeed;
- this.rb.velocity = transform.up * speed;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement