rj-action-library/Runtime/Interactions/CharacterController/CharacterController.cs

69 lines
1.5 KiB
C#

using Godot;
using System.Collections;
using System.Collections.Generic;
using Godot.Collections;
namespace Rokojori
{
[GlobalClass]
public partial class CharacterController:Node
{
[Export]
public CharacterBody3D body;
public enum CharacterUpdateMode
{
Process,
Physics_Process
}
[Export]
public CharacterUpdateMode characterUpdateMode = CharacterUpdateMode.Process;
[Export]
public Node actionsContainer;
[Export]
public Node3D graphics;
[Export]
public float rotationSmoothingDuration = 0;
Smoother rotationSmoother = new Smoother();
[Export]
public float positionSmoothingDuration = 0;
Smoother positionSmoother = new Smoother();
public float delta = 0;
public override void _Process( double delta )
{
if ( graphics == null || body == null )
{
return;
}
if ( CharacterUpdateMode.Process == characterUpdateMode )
{
this.delta = (float)delta;
Nodes.ForEach<CharacterControllerAction>( actionsContainer, a => Actions.Trigger( a ) );
}
positionSmoother.CopyPosition( graphics, body, rotationSmoothingDuration, delta );
rotationSmoother.CopyRotation( graphics, body, positionSmoothingDuration, delta );
}
public override void _PhysicsProcess( double delta )
{
if ( CharacterUpdateMode.Physics_Process == characterUpdateMode )
{
this.delta = (float)delta;
Nodes.ForEach<RJAction>( actionsContainer, a => Actions.Trigger( a ) );
}
}
}
}