-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMovingLight.cs
30 lines (25 loc) · 930 Bytes
/
MovingLight.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using Godot;
using System;
namespace FauxLight;
public partial class MovingLight : LightSource
{
[Export(PropertyHint.Range, "0.0, 50.0")]
public float Distance { get; set; } = 10;
[Export(PropertyHint.Range, "0.0, 5.0")]
public float Duration { get; set; } = 2;
[Export(PropertyHint.Range, "0.0, 1.0")]
public float Offset { get; set; }
private double Period => TwoPI / Duration;
private double TimeWithOffset => _time + (Period * Offset);
private const double TwoPI = 2 * Math.PI;
private double _time;
public override void _PhysicsProcess(double delta)
{
_time += (float)delta;
if (_time >= Period * 100)
_time -= Period * 100;
float posX = (float)Math.Sin((TimeWithOffset) * Period) * Distance;
float posY = (float)Math.Sin(TimeWithOffset * Period * 2) * (Distance * 0.5f);
Position = new Vector2(posX, posY);
}
}