2024-05-19 15:59:41 +00:00
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Godot;
|
|
|
|
|
|
2026-05-22 12:25:02 +00:00
|
|
|
using Rokojori.Extensions;
|
2024-05-19 15:59:41 +00:00
|
|
|
namespace Rokojori
|
|
|
|
|
{
|
|
|
|
|
public class Smoother
|
|
|
|
|
{
|
|
|
|
|
float overflowDelta = 0;
|
|
|
|
|
|
2025-07-11 08:16:45 +00:00
|
|
|
public static float SmoothTimeVariant( float value, float nextValue, float delta, float coefficient )
|
2025-01-08 18:46:17 +00:00
|
|
|
{
|
|
|
|
|
var lerpAmount = Mathf.Exp( -coefficient * delta );
|
|
|
|
|
return Mathf.Lerp( nextValue, value, lerpAmount );
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-11 08:16:45 +00:00
|
|
|
public static Vector2 SmoothTimeVariant( Vector2 value, Vector2 nextValue, float delta, float coefficient )
|
2025-01-08 18:46:17 +00:00
|
|
|
{
|
|
|
|
|
var lerpAmount = Mathf.Exp( -coefficient * delta );
|
|
|
|
|
return Math2D.Lerp( nextValue, value, lerpAmount );
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-11 08:16:45 +00:00
|
|
|
public static Vector3 SmoothTimeVariant( Vector3 value, Vector3 nextValue, float delta, float coefficient )
|
2025-01-08 18:46:17 +00:00
|
|
|
{
|
|
|
|
|
var lerpAmount = Mathf.Exp( -coefficient * delta );
|
|
|
|
|
return Math3D.Lerp( nextValue, value, lerpAmount );
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-19 15:59:41 +00:00
|
|
|
public float SmoothForDuration( float value, float nextValue, float duration, float delta, float processDelta = MathX.fps120Delta )
|
|
|
|
|
{
|
NPC Behaviors: movement/fight classes, Smoother Quaternion fix, ThirdPersonCamera lock blend split
- New Behavior/Movements: MoveOnPath, GoToPointBehavior, FleeBehavior, HidingSpot/HideAtSpotBehavior, NavigationBehaviorMovement; BehaviorMovement gained Flee/GetGlobalPosition, CharacterBodyBehaviorMovement moved from raw duration floats to Smoothing-resource exports.
- New Behavior/Fight: FightManager/FightSlot/JoinFight/LeaveFight/IsEngagedInFight/HasAttackPermission/IsAllyAttacking/FightState, mirroring the CameraManager/CameraSlot singleton+slot pattern.
- New Conditions/IsValueBelowThreshold (generic against NumberValue).
- Fixed Smoother.SmoothWithCoefficient(Quaternion...) not renormalizing after Slerp (crashed live after sustained use) and a MathX.SmoothingCoefficient argument-order bug in all three SmoothForDuration overloads.
- ThirdPersonCamera: lock engage/release now blends yaw/pitch (fixing a hard isLocked snap), fixed a yaw-staleness regression from that change, then split the single lock blend into independent focus (lockEngageSmoothing/lockReleaseSmoothing) and orientation (lockOrientationEngageSmoothing/lockOrientationReleaseSmoothing) blends.
- Includes carried-over uncommitted state from the earlier NPC/AI/Behaviours task (Behavior/StateMachine, Receptor/ReceptorBase/ReceptorControl, related Icons) that hadn't been committed yet.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-11 07:51:12 +00:00
|
|
|
var coefficient = MathX.SmoothingCoefficient( duration * 1000f, 0.1f, processDelta );
|
2024-12-01 17:07:41 +00:00
|
|
|
return SmoothWithCoefficient( value, nextValue, coefficient, delta, processDelta );
|
NPC Behaviors: movement/fight classes, Smoother Quaternion fix, ThirdPersonCamera lock blend split
- New Behavior/Movements: MoveOnPath, GoToPointBehavior, FleeBehavior, HidingSpot/HideAtSpotBehavior, NavigationBehaviorMovement; BehaviorMovement gained Flee/GetGlobalPosition, CharacterBodyBehaviorMovement moved from raw duration floats to Smoothing-resource exports.
- New Behavior/Fight: FightManager/FightSlot/JoinFight/LeaveFight/IsEngagedInFight/HasAttackPermission/IsAllyAttacking/FightState, mirroring the CameraManager/CameraSlot singleton+slot pattern.
- New Conditions/IsValueBelowThreshold (generic against NumberValue).
- Fixed Smoother.SmoothWithCoefficient(Quaternion...) not renormalizing after Slerp (crashed live after sustained use) and a MathX.SmoothingCoefficient argument-order bug in all three SmoothForDuration overloads.
- ThirdPersonCamera: lock engage/release now blends yaw/pitch (fixing a hard isLocked snap), fixed a yaw-staleness regression from that change, then split the single lock blend into independent focus (lockEngageSmoothing/lockReleaseSmoothing) and orientation (lockOrientationEngageSmoothing/lockOrientationReleaseSmoothing) blends.
- Includes carried-over uncommitted state from the earlier NPC/AI/Behaviours task (Behavior/StateMachine, Receptor/ReceptorBase/ReceptorControl, related Icons) that hadn't been committed yet.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-11 07:51:12 +00:00
|
|
|
}
|
2024-05-19 15:59:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
public float SmoothWithCoefficient( float value, float nextValue, float coefficient, float delta, float processDelta = MathX.fps120Delta )
|
|
|
|
|
{
|
|
|
|
|
overflowDelta += delta;
|
|
|
|
|
|
|
|
|
|
while ( overflowDelta > processDelta )
|
|
|
|
|
{
|
|
|
|
|
value += coefficient * ( nextValue - value );
|
|
|
|
|
overflowDelta -= processDelta;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Quaternion SmoothForDuration( Quaternion value, Quaternion nextValue, float duration, float delta, float processDelta = MathX.fps120Delta )
|
|
|
|
|
{
|
NPC Behaviors: movement/fight classes, Smoother Quaternion fix, ThirdPersonCamera lock blend split
- New Behavior/Movements: MoveOnPath, GoToPointBehavior, FleeBehavior, HidingSpot/HideAtSpotBehavior, NavigationBehaviorMovement; BehaviorMovement gained Flee/GetGlobalPosition, CharacterBodyBehaviorMovement moved from raw duration floats to Smoothing-resource exports.
- New Behavior/Fight: FightManager/FightSlot/JoinFight/LeaveFight/IsEngagedInFight/HasAttackPermission/IsAllyAttacking/FightState, mirroring the CameraManager/CameraSlot singleton+slot pattern.
- New Conditions/IsValueBelowThreshold (generic against NumberValue).
- Fixed Smoother.SmoothWithCoefficient(Quaternion...) not renormalizing after Slerp (crashed live after sustained use) and a MathX.SmoothingCoefficient argument-order bug in all three SmoothForDuration overloads.
- ThirdPersonCamera: lock engage/release now blends yaw/pitch (fixing a hard isLocked snap), fixed a yaw-staleness regression from that change, then split the single lock blend into independent focus (lockEngageSmoothing/lockReleaseSmoothing) and orientation (lockOrientationEngageSmoothing/lockOrientationReleaseSmoothing) blends.
- Includes carried-over uncommitted state from the earlier NPC/AI/Behaviours task (Behavior/StateMachine, Receptor/ReceptorBase/ReceptorControl, related Icons) that hadn't been committed yet.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-11 07:51:12 +00:00
|
|
|
var coefficient = MathX.SmoothingCoefficient( duration * 1000f, 0.1f, processDelta );
|
2024-12-01 17:07:41 +00:00
|
|
|
return SmoothWithCoefficient( value, nextValue, coefficient, delta, processDelta );
|
NPC Behaviors: movement/fight classes, Smoother Quaternion fix, ThirdPersonCamera lock blend split
- New Behavior/Movements: MoveOnPath, GoToPointBehavior, FleeBehavior, HidingSpot/HideAtSpotBehavior, NavigationBehaviorMovement; BehaviorMovement gained Flee/GetGlobalPosition, CharacterBodyBehaviorMovement moved from raw duration floats to Smoothing-resource exports.
- New Behavior/Fight: FightManager/FightSlot/JoinFight/LeaveFight/IsEngagedInFight/HasAttackPermission/IsAllyAttacking/FightState, mirroring the CameraManager/CameraSlot singleton+slot pattern.
- New Conditions/IsValueBelowThreshold (generic against NumberValue).
- Fixed Smoother.SmoothWithCoefficient(Quaternion...) not renormalizing after Slerp (crashed live after sustained use) and a MathX.SmoothingCoefficient argument-order bug in all three SmoothForDuration overloads.
- ThirdPersonCamera: lock engage/release now blends yaw/pitch (fixing a hard isLocked snap), fixed a yaw-staleness regression from that change, then split the single lock blend into independent focus (lockEngageSmoothing/lockReleaseSmoothing) and orientation (lockOrientationEngageSmoothing/lockOrientationReleaseSmoothing) blends.
- Includes carried-over uncommitted state from the earlier NPC/AI/Behaviours task (Behavior/StateMachine, Receptor/ReceptorBase/ReceptorControl, related Icons) that hadn't been committed yet.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-11 07:51:12 +00:00
|
|
|
}
|
2024-05-19 15:59:41 +00:00
|
|
|
|
|
|
|
|
public Quaternion SmoothWithCoefficient( Quaternion value, Quaternion nextValue, float coefficient, float delta, float processDelta = MathX.fps120Delta )
|
|
|
|
|
{
|
|
|
|
|
overflowDelta += delta;
|
|
|
|
|
|
|
|
|
|
while ( overflowDelta > processDelta )
|
|
|
|
|
{
|
NPC Behaviors: movement/fight classes, Smoother Quaternion fix, ThirdPersonCamera lock blend split
- New Behavior/Movements: MoveOnPath, GoToPointBehavior, FleeBehavior, HidingSpot/HideAtSpotBehavior, NavigationBehaviorMovement; BehaviorMovement gained Flee/GetGlobalPosition, CharacterBodyBehaviorMovement moved from raw duration floats to Smoothing-resource exports.
- New Behavior/Fight: FightManager/FightSlot/JoinFight/LeaveFight/IsEngagedInFight/HasAttackPermission/IsAllyAttacking/FightState, mirroring the CameraManager/CameraSlot singleton+slot pattern.
- New Conditions/IsValueBelowThreshold (generic against NumberValue).
- Fixed Smoother.SmoothWithCoefficient(Quaternion...) not renormalizing after Slerp (crashed live after sustained use) and a MathX.SmoothingCoefficient argument-order bug in all three SmoothForDuration overloads.
- ThirdPersonCamera: lock engage/release now blends yaw/pitch (fixing a hard isLocked snap), fixed a yaw-staleness regression from that change, then split the single lock blend into independent focus (lockEngageSmoothing/lockReleaseSmoothing) and orientation (lockOrientationEngageSmoothing/lockOrientationReleaseSmoothing) blends.
- Includes carried-over uncommitted state from the earlier NPC/AI/Behaviours task (Behavior/StateMachine, Receptor/ReceptorBase/ReceptorControl, related Icons) that hadn't been committed yet.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-11 07:51:12 +00:00
|
|
|
value = value.Slerp( nextValue, coefficient ).Normalized();
|
2024-05-19 15:59:41 +00:00
|
|
|
overflowDelta -= processDelta;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return value;
|
2024-12-01 17:07:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Vector3 SmoothForDuration( Vector3 value, Vector3 nextValue, float duration, float delta, float processDelta = MathX.fps120Delta )
|
|
|
|
|
{
|
NPC Behaviors: movement/fight classes, Smoother Quaternion fix, ThirdPersonCamera lock blend split
- New Behavior/Movements: MoveOnPath, GoToPointBehavior, FleeBehavior, HidingSpot/HideAtSpotBehavior, NavigationBehaviorMovement; BehaviorMovement gained Flee/GetGlobalPosition, CharacterBodyBehaviorMovement moved from raw duration floats to Smoothing-resource exports.
- New Behavior/Fight: FightManager/FightSlot/JoinFight/LeaveFight/IsEngagedInFight/HasAttackPermission/IsAllyAttacking/FightState, mirroring the CameraManager/CameraSlot singleton+slot pattern.
- New Conditions/IsValueBelowThreshold (generic against NumberValue).
- Fixed Smoother.SmoothWithCoefficient(Quaternion...) not renormalizing after Slerp (crashed live after sustained use) and a MathX.SmoothingCoefficient argument-order bug in all three SmoothForDuration overloads.
- ThirdPersonCamera: lock engage/release now blends yaw/pitch (fixing a hard isLocked snap), fixed a yaw-staleness regression from that change, then split the single lock blend into independent focus (lockEngageSmoothing/lockReleaseSmoothing) and orientation (lockOrientationEngageSmoothing/lockOrientationReleaseSmoothing) blends.
- Includes carried-over uncommitted state from the earlier NPC/AI/Behaviours task (Behavior/StateMachine, Receptor/ReceptorBase/ReceptorControl, related Icons) that hadn't been committed yet.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-11 07:51:12 +00:00
|
|
|
var coefficient = MathX.SmoothingCoefficient( duration * 1000f, 0.1f, processDelta );
|
2024-12-01 17:07:41 +00:00
|
|
|
return SmoothWithCoefficient( value, nextValue, coefficient, delta, processDelta );
|
NPC Behaviors: movement/fight classes, Smoother Quaternion fix, ThirdPersonCamera lock blend split
- New Behavior/Movements: MoveOnPath, GoToPointBehavior, FleeBehavior, HidingSpot/HideAtSpotBehavior, NavigationBehaviorMovement; BehaviorMovement gained Flee/GetGlobalPosition, CharacterBodyBehaviorMovement moved from raw duration floats to Smoothing-resource exports.
- New Behavior/Fight: FightManager/FightSlot/JoinFight/LeaveFight/IsEngagedInFight/HasAttackPermission/IsAllyAttacking/FightState, mirroring the CameraManager/CameraSlot singleton+slot pattern.
- New Conditions/IsValueBelowThreshold (generic against NumberValue).
- Fixed Smoother.SmoothWithCoefficient(Quaternion...) not renormalizing after Slerp (crashed live after sustained use) and a MathX.SmoothingCoefficient argument-order bug in all three SmoothForDuration overloads.
- ThirdPersonCamera: lock engage/release now blends yaw/pitch (fixing a hard isLocked snap), fixed a yaw-staleness regression from that change, then split the single lock blend into independent focus (lockEngageSmoothing/lockReleaseSmoothing) and orientation (lockOrientationEngageSmoothing/lockOrientationReleaseSmoothing) blends.
- Includes carried-over uncommitted state from the earlier NPC/AI/Behaviours task (Behavior/StateMachine, Receptor/ReceptorBase/ReceptorControl, related Icons) that hadn't been committed yet.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-11 07:51:12 +00:00
|
|
|
}
|
2024-12-01 17:07:41 +00:00
|
|
|
|
|
|
|
|
public Vector3 SmoothWithCoefficient( Vector3 value, Vector3 nextValue, float coefficient, float delta, float processDelta = MathX.fps120Delta )
|
|
|
|
|
{
|
|
|
|
|
overflowDelta += delta;
|
|
|
|
|
|
|
|
|
|
while ( overflowDelta > processDelta )
|
|
|
|
|
{
|
|
|
|
|
value = value.Lerp( nextValue, coefficient );
|
|
|
|
|
overflowDelta -= processDelta;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void CopyPosition( Node3D source, Node3D target, float duration, float delta )
|
|
|
|
|
{
|
|
|
|
|
target.GlobalPosition = SmoothForDuration( target.GlobalPosition, source.GlobalPosition, duration, delta );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void CopyPosition( Node3D source, Node3D target, float duration, double delta )
|
|
|
|
|
{
|
|
|
|
|
CopyPosition( source, target, duration, (float) delta );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void CopyRotation( Node3D source, Node3D target, float duration, float delta )
|
|
|
|
|
{
|
2025-10-24 11:38:51 +00:00
|
|
|
target.SetGlobalQuaternion( SmoothForDuration( target.GlobalQuaternion(), source.GlobalQuaternion(), duration, delta ) );
|
2024-12-01 17:07:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void CopyRotation( Node3D source, Node3D target, float duration, double delta )
|
|
|
|
|
{
|
|
|
|
|
CopyRotation( source, target, duration, (float) delta );
|
|
|
|
|
}
|
2024-05-19 15:59:41 +00:00
|
|
|
}
|
|
|
|
|
}
|