Galaxy Generator
This commit is contained in:
34
Assets/PlanetMove.cs
Normal file
34
Assets/PlanetMove.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlanetMove : MonoBehaviour
|
||||
{
|
||||
public float rotationSpeed = 1f; // Geschwindigkeit der Rotation
|
||||
public float radius = 5f; // Radius des Kreises
|
||||
private float angle = 0f; // Aktueller Winkel im Kreis
|
||||
private Vector2 centerPosition; // Position des Zentrums des Kreises
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
centerPosition = transform.parent.position; // Position des Zentrums
|
||||
transform.position = GetPositionOnCircle(angle); // Setze die Startposition
|
||||
}
|
||||
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
angle += rotationSpeed * Time.deltaTime; // Aktualisiere den Winkel basierend auf der Geschwindigkeit
|
||||
transform.position = GetPositionOnCircle(angle); // Berechne die neue Position des Planeten
|
||||
}
|
||||
|
||||
Vector3 GetPositionOnCircle(float angle)
|
||||
{
|
||||
float xPos = centerPosition.x + Mathf.Sin(angle) * radius; // X-Position auf dem Kreis
|
||||
float yPos = centerPosition.y + Mathf.Cos(angle) * radius; // Y-Position auf dem Kreis
|
||||
return new Vector3(xPos, yPos, 0f); // Position als Vektor zur<75>ckgeben
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user