Advertisement
Guest User

Homing Missle Script {FE{

a guest
Feb 17th, 2020
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. using UnityEngine;
  2. public class HomingMissleScript : MonoBehaviour
  3. {
  4. public Transform target;
  5. public float speed;
  6. public Rigidbody rb;
  7. public float rotateSpeed;
  8. public void FixedUpdate()
  9. {
  10. Vector3 direction this.target.position - this.rb.position;
  11. this.direction.Normalize();
  12. float rotateAmount = Vector3.Cross(direction, transform.up).z;
  13. this.rb.angularVelocity = -rotateAmount * rotateSpeed;
  14. this.rb.velocity = transform.up * speed;
  15. }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement