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 = 20f; // 20 degrees per second
- // 2. for rotating around the "Sun"
- public Transform pivotPoint; // The point around which the sphere will orbit
- public float rotationSunSpeed = 10f; // Degrees per second
- public float startingDistance = 50f; // Initial distance from the pivot point
- void Start()
- {
- // Calculate the initial position based on the starting distance
- Vector3 offset = transform.position - pivotPoint.position;
- offset = offset.normalized * startingDistance;
- transform.position = pivotPoint.position + offset;
- }
- 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