mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
Player movement and camera
This commit is contained in:
parent
ed656f00bb
commit
a324f2e347
43 changed files with 1777 additions and 316 deletions
|
|
@ -81,52 +81,7 @@ public partial class Active : BaseState<PlayerState, CharacterBody3D>
|
|||
{
|
||||
base.ProcessState(delta);
|
||||
|
||||
_movementDirection = _inputProvider.GetMovementInput().Normalized();
|
||||
_isStrafing = _inputProvider.GetStrafePressed();
|
||||
|
||||
// Toggle visibility of the hitbox sprite based on strafing
|
||||
_hitboxSpriteProvider.SetVisibility(_isStrafing);
|
||||
|
||||
var rightStickInput = _inputProvider.GetAimInput().Normalized();
|
||||
|
||||
// Update Facing Direction
|
||||
// if (!_isStrafing)
|
||||
// {
|
||||
if (rightStickInput.Length() > 0.1f) // If the right stick is moved
|
||||
{
|
||||
FacingDirection = rightStickInput;
|
||||
}
|
||||
else if (_movementDirection != Vector2.Zero) // Fall back to movement direction
|
||||
{
|
||||
FacingDirection = _movementDirection;
|
||||
}
|
||||
// }
|
||||
|
||||
_animationProvider.SetAnimationSpeed(MainObject.Velocity);
|
||||
_animationProvider.SetAnimation(FacingDirection);
|
||||
|
||||
HandleWeaponSwitch();
|
||||
_weaponProvider.Update(delta);
|
||||
|
||||
//_crosshairProvider.UpdatePosition(FacingDirection);
|
||||
|
||||
HandleShoot();
|
||||
|
||||
HandleInteraction();
|
||||
// FindInteractable();
|
||||
|
||||
// _crosshair.Position = CalculateCrosshairPosition();
|
||||
|
||||
if (_inputProvider.GetInventoryJustPressed())
|
||||
{
|
||||
GameManager.Instance.ChangeState(GameState.Inventory);
|
||||
}
|
||||
|
||||
if (_inputProvider.GetPauseJustPressed())
|
||||
{
|
||||
//CallDeferred(MethodName.PauseDeferred);
|
||||
PauseDeferred();
|
||||
}
|
||||
}
|
||||
|
||||
private void PauseDeferred()
|
||||
|
|
@ -134,32 +89,5 @@ public partial class Active : BaseState<PlayerState, CharacterBody3D>
|
|||
GameManager.Instance.Pause();
|
||||
}
|
||||
|
||||
// private void HandleShoot()
|
||||
// {
|
||||
// if (_inputProvider.GetReloadJustPressed())
|
||||
// {
|
||||
// _weaponProvider.Reload();
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// if (!_inputProvider.GetShootPressed()) return;
|
||||
// _weaponProvider.Shoot(this.FacingDirection);
|
||||
// }
|
||||
//
|
||||
// private void HandleInteraction()
|
||||
// {
|
||||
// _activationProvider.HandleInteraction();
|
||||
// }
|
||||
//
|
||||
// private void HandleWeaponSwitch()
|
||||
// {
|
||||
// if (_inputProvider.GetWeaponNextJustPressed())
|
||||
// {
|
||||
// _weaponProvider.NextWeapon();
|
||||
// }
|
||||
// else if (_inputProvider.GetWeaponPreviousJustPressed())
|
||||
// {
|
||||
// _weaponProvider.PreviousWeapon();
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
@ -32,6 +32,6 @@ public partial class Init : BaseState<PlayerState, CharacterBody3D>
|
|||
private async Task AutoSwitchToStart()
|
||||
{
|
||||
await Task.Delay(500);
|
||||
//StateMachine.SetState(PlayerState.Active);
|
||||
StateMachine.SetState(PlayerState.Active);
|
||||
}
|
||||
}
|
||||
|
|
@ -12,6 +12,8 @@ public partial class IsoMovementModule : ModuleBase<PlayerState, CharacterBody3D
|
|||
[Export] public int StrafeSpeed { get; set; } = 35;
|
||||
[Export] public float Acceleration = 8f;
|
||||
[Export] public float Deceleration = 8f;
|
||||
[Export] public float Gravity = -9.8f;
|
||||
[Export] public float FallSpeed = 20f;
|
||||
|
||||
private bool _isStrafing;
|
||||
private float _accelerationPerSecond;
|
||||
|
|
@ -41,16 +43,38 @@ public partial class IsoMovementModule : ModuleBase<PlayerState, CharacterBody3D
|
|||
|
||||
public override void Process(double delta)
|
||||
{
|
||||
var movementInput = _inputProvider.GetMovementInput();
|
||||
|
||||
_isStrafing = _inputProvider.GetStrafePressed();
|
||||
var rightStickInput = _inputProvider.GetAimInput().Normalized();
|
||||
|
||||
// Update Facing Direction
|
||||
// if (!_isStrafing)
|
||||
// {
|
||||
if (rightStickInput.Length() > 0.1f) // If the right stick is moved
|
||||
{
|
||||
PlayerStorage.FacingDirection = rightStickInput;
|
||||
}
|
||||
else if (movementInput != Vector2.Zero) // Fall back to movement direction
|
||||
{
|
||||
PlayerStorage.FacingDirection = movementInput;
|
||||
}
|
||||
// }
|
||||
|
||||
var rotatedMovementDirection = movementInput.Rotated(Mathf.DegToRad(-45f));
|
||||
|
||||
PlayerStorage.MovementDirection = new Vector3(rotatedMovementDirection.X, 0, rotatedMovementDirection.Y);
|
||||
}
|
||||
|
||||
public override void PhysicsProcess(double delta)
|
||||
{
|
||||
|
||||
var frameVelocity = MainObject.Velocity;
|
||||
|
||||
if (_isStrafing)
|
||||
{
|
||||
// Instant movement at strafe speed
|
||||
MainObject.Velocity = PlayerStorage.MovementDirection * StrafeSpeed;
|
||||
frameVelocity = PlayerStorage.MovementDirection * StrafeSpeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -58,16 +82,22 @@ public partial class IsoMovementModule : ModuleBase<PlayerState, CharacterBody3D
|
|||
|
||||
if (PlayerStorage.MovementDirection != Vector3.Zero)
|
||||
{
|
||||
MainObject.Velocity = MainObject.Velocity.MoveToward(targetVelocity, Acceleration * (float)delta);
|
||||
frameVelocity = frameVelocity.MoveToward(targetVelocity, Acceleration * (float)delta);
|
||||
}
|
||||
else
|
||||
{
|
||||
MainObject.Velocity = MainObject.Velocity.MoveToward(Vector3.Zero, Deceleration * (float)delta);
|
||||
frameVelocity = frameVelocity.MoveToward(Vector3.Zero, Deceleration * (float)delta);
|
||||
}
|
||||
}
|
||||
|
||||
//MainObject.Velocity += _movementDirection * MovementSpeed;
|
||||
|
||||
var velocityY = Mathf.Clamp(frameVelocity.Y + Gravity * (float)delta, -FallSpeed, FallSpeed);
|
||||
|
||||
frameVelocity.Y = velocityY;
|
||||
|
||||
MainObject.Velocity = frameVelocity;
|
||||
|
||||
MainObject.MoveAndSlide();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue