mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-09 14:15:55 +00:00
Isometric implementation
This commit is contained in:
parent
1434f7aa6d
commit
ed656f00bb
92 changed files with 2834 additions and 223 deletions
73
Scripts/Components/FSM/3DPlayer/IsoMovementModule.cs
Normal file
73
Scripts/Components/FSM/3DPlayer/IsoMovementModule.cs
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
using Cirno.Scripts.Components.Actors;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.FSM._3DPlayer;
|
||||
|
||||
public partial class IsoMovementModule : ModuleBase<PlayerState, CharacterBody3D>
|
||||
{
|
||||
[Export] public IsoPlayerStorageModule PlayerStorage { get; private set; }
|
||||
[Export] private InputProvider _inputProvider;
|
||||
|
||||
[Export] public int Speed { get; set; } = 45;
|
||||
[Export] public int StrafeSpeed { get; set; } = 35;
|
||||
[Export] public float Acceleration = 8f;
|
||||
[Export] public float Deceleration = 8f;
|
||||
|
||||
private bool _isStrafing;
|
||||
private float _accelerationPerSecond;
|
||||
private float _decelerationPerSecond;
|
||||
|
||||
public int MovementSpeed => _isStrafing ? StrafeSpeed : Speed;
|
||||
|
||||
private IStateMachine<PlayerState, CharacterBody3D> _stateMachine;
|
||||
|
||||
private CharacterBody3D MainObject => _stateMachine.MainObject;
|
||||
|
||||
public override void EnterState(PlayerState state)
|
||||
{
|
||||
_accelerationPerSecond = Speed / Acceleration;
|
||||
_decelerationPerSecond = Speed / Deceleration;
|
||||
}
|
||||
|
||||
public override void ExitState(PlayerState state)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void Init(IStateMachine<PlayerState, CharacterBody3D> machine)
|
||||
{
|
||||
_stateMachine = machine;
|
||||
}
|
||||
|
||||
public override void Process(double delta)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void PhysicsProcess(double delta)
|
||||
{
|
||||
|
||||
if (_isStrafing)
|
||||
{
|
||||
// Instant movement at strafe speed
|
||||
MainObject.Velocity = PlayerStorage.MovementDirection * StrafeSpeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector3 targetVelocity = PlayerStorage.MovementDirection * Speed;
|
||||
|
||||
if (PlayerStorage.MovementDirection != Vector3.Zero)
|
||||
{
|
||||
MainObject.Velocity = MainObject.Velocity.MoveToward(targetVelocity, Acceleration * (float)delta);
|
||||
}
|
||||
else
|
||||
{
|
||||
MainObject.Velocity = MainObject.Velocity.MoveToward(Vector3.Zero, Deceleration * (float)delta);
|
||||
}
|
||||
}
|
||||
|
||||
//MainObject.Velocity += _movementDirection * MovementSpeed;
|
||||
|
||||
MainObject.MoveAndSlide();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue