44 lines
1.1 KiB
C#
44 lines
1.1 KiB
C#
using Godot;
|
|
|
|
public partial class StarNode : StaticBody3D
|
|
{
|
|
public Star StarData { get; set; }
|
|
|
|
private Vector3 lastFrameCoordinates = Vector3.Zero;
|
|
private Vector3 lastFrameRotation = Vector3.Zero;
|
|
|
|
private Vector3 velocityOffset = Vector3.Zero;
|
|
private Vector3 angularVelocityOffset = Vector3.Zero;
|
|
|
|
public override void _Ready()
|
|
{
|
|
GlobalPosition = StarData.LocalCoordinates + StarData.SectorOffset;
|
|
GlobalRotation = StarData.Rotation;
|
|
}
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
if (StarData.LocalCoordinates == lastFrameCoordinates)
|
|
{
|
|
velocityOffset += StarData.Velocity * delta;
|
|
}
|
|
else
|
|
{
|
|
lastFrameCoordinates = StarData.LocalCoordinates;
|
|
velocityOffset = Vector3.Zero;
|
|
}
|
|
|
|
if (StarData.Rotation == lastFrameRotation)
|
|
{
|
|
angularVelocityOffset += StarData.AngularVelocity * delta;
|
|
}
|
|
else
|
|
{
|
|
lastFrameRotation = StarData.Rotation;
|
|
angularVelocityOffset = Vector3.Zero;
|
|
}
|
|
|
|
GlobalPosition = StarData.LocalCoordinates + StarData.SectorOffset + velocityOffset;
|
|
GlobalRotation = StarData.Rotation + angularVelocityOffset;
|
|
}
|
|
}
|