Files
ScienceLab.GravityForce/Assets/Materials/Scripts/MoonGravityForce.cs
2026-03-17 13:40:09 +02:00

42 lines
1.1 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoonGravityForce : MonoBehaviour
{
[Header("Швидкість обертання навколо Землі")]
[Range(0f, 100f)]
[SerializeField] private float orbitSpeed = 0.55f;
[Header("Нахил осі Місяця")]
[Range(0f, 180f)]
[SerializeField] private float axialTilt = 6.68f;
private PlanetSpin _parentSpin;
private Transform _parentTransform;
void Start()
{
_parentTransform = transform.parent;
_parentSpin = _parentTransform.GetComponent<PlanetSpin>();
transform.localRotation = Quaternion.Euler(0f, 0f, axialTilt);
}
void Update()
{
float parentRotationSpeed = _parentSpin != null ? _parentSpin.RotationSpeed : 0f;
float compensatedOrbit = orbitSpeed - parentRotationSpeed;
transform.RotateAround(
_parentTransform.position,
Vector3.up,
compensatedOrbit * Time.deltaTime
);
transform.LookAt(_parentTransform.position);
}
}