Advertisement
Guest User

aiming at target

a guest
Jun 23rd, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. public Transform target;
  2. public clickme _active;
  3. public float degrees, distance;
  4. public GameObject ebullet;
  5. public Transform Bullet_position;
  6.  
  7. // Update is called once per frame
  8. void Update()
  9. {
  10. target = _active.aiming_point;
  11. distance = Vector3.Distance(target.position, transform.position);
  12.  
  13. if (target != null)
  14. {
  15. degrees = Vector3.Angle(target.position - transform.position, transform.forward);
  16. }
  17. else
  18. {
  19.  
  20. }
  21.  
  22. if (_active.actives == false)
  23. {
  24.  
  25. if (degrees <= 50 && target != null)
  26. {
  27.  
  28. Quaternion rotation = Quaternion.LookRotation(target.position - transform.position);
  29. transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * 3.0f);
  30. if (degrees <= 10)
  31. {
  32. GameObject bullets = Instantiate(ebullet) as GameObject;
  33. bullets.transform.position = Bullet_position.transform.position * 1;
  34. Rigidbody rb = bullets.GetComponent<Rigidbody>();
  35. rb.velocity = transform.forward * 20;
  36. Destroy(bullets, 4f);
  37.  
  38. }
  39. }
  40.  
  41. }
  42. else
  43. {
  44. Quaternion rotation = Quaternion.LookRotation(transform.forward);
  45. transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * 1.0f);
  46. }
  47.  
  48. } // end update
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement