Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Rotation : MonoBehaviour
- {
- // 1. rotating a sphere around it's own axis
- public float rotationSpeed = 3f; // 3 degrees per second
- // 2. for rotating around the "Sun"
- public Transform pivotPoint; // The point around which the sphere will orbit
- public float rotationSunSpeed = 2f; // Degrees per second
- void Update()
- {
- // 1. Rotate the sphere by the specified speed around its up (Y) axis
- transform.Rotate(Vector3.up * rotationSpeed * Time.deltaTime);
- // 2. for rotating around tHe Sun
- // Calculate the rotation axis using the pivot point
- Vector3 pivotToSphere = transform.position - pivotPoint.position;
- Vector3 rotationAxis = Vector3.up; // You can change this to a different axis if needed
- // Rotate the sphere around the pivot point
- transform.RotateAround(pivotPoint.position, rotationAxis, rotationSunSpeed * Time.deltaTime);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement