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

75 lines
1.9 KiB
C#
Raw Normal View History

2024-12-01 17:07:41 +00:00
using Godot;
using System.Collections;
using System.Collections.Generic;
using Godot.Collections;
namespace Rokojori
{
2025-05-21 20:44:28 +00:00
[Tool]
2025-05-27 06:51:48 +00:00
[GlobalClass, Icon("res://addons/rokojori_action_library/Icons/CharacterController.svg")]
2024-12-01 17:07:41 +00:00
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]
2025-05-21 20:44:28 +00:00
public Smoothing rotationSmoothing;
2024-12-01 17:07:41 +00:00
[Export]
2025-05-21 20:44:28 +00:00
public Smoothing positionSmoothing;
2024-12-01 17:07:41 +00:00
public float delta = 0;
public override void _Process( double delta )
{
if ( graphics == null || body == null )
{
return;
}
if ( CharacterUpdateMode.Process == characterUpdateMode )
{
2025-05-27 06:51:48 +00:00
ProcessActions( (float) delta );
2024-12-01 17:07:41 +00:00
}
2025-01-03 12:09:23 +00:00
// positionSmoother.CopyPosition( graphics, body, rotationSmoothingDuration, delta );
// rotationSmoother.CopyRotation( graphics, body, positionSmoothingDuration, delta );
2025-05-21 20:44:28 +00:00
graphics.GlobalPosition = Smoothing.Apply( positionSmoothing, body.GlobalPosition, this.delta );
graphics.SetGlobalQuaternion( Smoothing.Apply( rotationSmoothing, body.GetGlobalQuaternion(), this.delta ) );
// Pose.CopyTo( body, graphics );
2024-12-01 17:07:41 +00:00
}
public override void _PhysicsProcess( double delta )
{
if ( CharacterUpdateMode.Physics_Process == characterUpdateMode )
{
2025-05-27 06:51:48 +00:00
ProcessActions( (float) delta );
2024-12-01 17:07:41 +00:00
}
}
2025-05-27 06:51:48 +00:00
void ProcessActions( float delta )
{
this.delta = (float) delta;
var container = actionsContainer == null ? this : actionsContainer;
Nodes.ForEachDirectChild<CharacterControllerAction>( container, Action.Trigger );
}
2024-12-01 17:07:41 +00:00
}
}