70 lines
1.0 KiB
C#
70 lines
1.0 KiB
C#
|
|
using Godot;
|
|
using Rokojori;
|
|
|
|
namespace GameJam
|
|
{
|
|
[GlobalClass]
|
|
public partial class MoveTo:RJSequenceAction
|
|
{
|
|
[Export]
|
|
public Node3D target;
|
|
|
|
[Export]
|
|
public Node3D endPosition;
|
|
|
|
[Export]
|
|
public float duration;
|
|
|
|
float elapsed = 0f;
|
|
bool running = false;
|
|
Vector3 start;
|
|
|
|
|
|
public override void _OnTrigger()
|
|
{
|
|
if ( running )
|
|
{
|
|
return;
|
|
}
|
|
|
|
var id = DispatchStart();
|
|
elapsed = 0;
|
|
running = true;
|
|
|
|
start = target.GlobalPosition;
|
|
|
|
}
|
|
|
|
public override void _Process( double delta )
|
|
{
|
|
if ( ! running )
|
|
{
|
|
return;
|
|
}
|
|
|
|
elapsed += (float) delta;
|
|
|
|
var phase = elapsed / duration;
|
|
|
|
var value = MathX.Clamp01( phase );
|
|
|
|
var sine = Mathf.Sin( phase * 40 );
|
|
var offset = sine * Vector3.Right;
|
|
var lerped = start.Lerp( endPosition.GlobalPosition + offset, value );
|
|
|
|
target.GlobalPosition = lerped;
|
|
|
|
if ( phase >= 1 )
|
|
{
|
|
running = false;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
} |