rj-action-library/Runtime/Actions/Node3D/DistributeChildren.cs

49 lines
890 B
C#
Raw Normal View History

2024-08-04 09:08:12 +00:00
using Godot;
namespace Rokojori
{
[GlobalClass, Tool ]
2025-01-08 18:46:17 +00:00
public partial class DistributeChildren : Action
2024-08-04 09:08:12 +00:00
{
[Export]
public Node3D target;
[Export]
public Node3D start;
[Export]
public Node3D end;
public override void _Process( double delta )
{
_OnTrigger();
}
2025-01-08 18:46:17 +00:00
protected override void _OnTrigger()
2024-08-04 09:08:12 +00:00
{
if ( start == null || end == null || target == null )
{
return;
}
var children = Nodes.GetDirectChildren<Node3D>( target );
var startPosition = start.GlobalPosition;
var endPosition = end.GlobalPosition;
for ( int i = 0; i < children.Count; i++ )
{
var lerpState = i / ( children.Count - 1f );
var childPosition = startPosition.Lerp( endPosition, lerpState );
children[ i ].GlobalPosition = childPosition;
}
}
}
}