Advertisement
MariuszPoz

Untitled

Oct 27th, 2023
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | Gaming | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Rotation : MonoBehaviour
  6. {
  7.    
  8.     // 1. rotating a sphere around it's own axis
  9.     public float rotationSpeed = 3f; // 3 degrees per second
  10.  
  11.     // 2. for rotating around the "Sun"
  12.  
  13.     public Transform pivotPoint; // The point around which the sphere will orbit
  14.     public float rotationSunSpeed = 2f; // Degrees per second
  15.  
  16.     void Update()
  17.     {
  18.         // 1. Rotate the sphere by the specified speed around its up (Y) axis
  19.         transform.Rotate(Vector3.up * rotationSpeed * Time.deltaTime);
  20.  
  21.         // 2. for rotating around tHe Sun
  22.  
  23.         // Calculate the rotation axis using the pivot point
  24.         Vector3 pivotToSphere = transform.position - pivotPoint.position;
  25.         Vector3 rotationAxis = Vector3.up; // You can change this to a different axis if needed
  26.  
  27.         // Rotate the sphere around the pivot point
  28.         transform.RotateAround(pivotPoint.position, rotationAxis, rotationSunSpeed * Time.deltaTime);
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement