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

66 lines
1.4 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/CharacterControllerAction.svg")]
2025-01-08 18:46:17 +00:00
public partial class CharacterControllerAction:Action
2024-12-01 17:07:41 +00:00
{
2025-07-25 08:13:35 +00:00
[Export]
public bool enabled = true;
2025-10-24 11:38:51 +00:00
CharacterController _controller;
public CharacterController controller => _controller;
2024-12-01 17:07:41 +00:00
2025-07-25 08:13:35 +00:00
[Export]
public Condition condition;
[Export]
public SceneCondition sceneCondition;
2025-10-24 11:38:51 +00:00
public void SetCharacterController( CharacterController cc )
{
_controller = cc;
}
2025-07-25 08:13:35 +00:00
2024-12-01 17:07:41 +00:00
public CharacterBody3D body => controller.body;
2025-10-24 11:38:51 +00:00
public void AddVelocity( Vector3 velocity, float delta = -1 )
{
delta = delta < 0 ? controller.delta : delta;
body.Velocity += velocity * delta;
}
public void SetScaledVelocity( float scale )
2025-01-03 12:09:23 +00:00
{
2025-10-24 11:38:51 +00:00
body.Velocity *= scale;
2025-01-03 12:09:23 +00:00
}
2025-10-24 11:38:51 +00:00
public void SetVelocity( Vector3 velocity, float delta = -1 )
2025-01-03 12:09:23 +00:00
{
2025-10-24 11:38:51 +00:00
delta = delta < 0 ? controller.delta : delta;
body.Velocity = velocity * delta;
2025-01-03 12:09:23 +00:00
}
2025-10-24 11:38:51 +00:00
public void Velocity( Vector3 velocity, bool replace, float delta = -1 )
2024-12-01 17:07:41 +00:00
{
if ( replace )
{
2025-10-24 11:38:51 +00:00
SetVelocity( velocity, delta );
2024-12-01 17:07:41 +00:00
}
else
{
2025-10-24 11:38:51 +00:00
AddVelocity( velocity, delta );
2024-12-01 17:07:41 +00:00
}
}
}
}