Advertisement
LeeMace

Object orbits around target

Jun 26th, 2023
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.47 KB | Gaming | 0 0
  1. public class GravityOrbitScript : MonoBehaviour
  2. {
  3.     public Transform target;
  4.     void Update() {
  5.         Vector3 relativePos = (target.position + new Vector3(0, 1.5f, 0)) - transform.position;
  6.         Quaternion rotation = Quaternion.LookRotation(relativePos);
  7.  
  8.         Quaternion current = transform.localRotation;
  9.  
  10.         transform.localRotation = Quaternion.Slerp(current, rotation, Time.deltaTime);
  11.         transform.Translate(0, 0, 10 * Time.deltaTime);
  12.     }
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement