36 lines
1.2 KiB
C#
36 lines
1.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class PlanetMove : MonoBehaviour
|
|
{
|
|
public int PlayerID;
|
|
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ückgeben
|
|
}
|
|
|
|
}
|