Better gravity handling

This commit is contained in:
Marco 2025-06-29 12:35:19 +02:00
commit 16992c2bea
4 changed files with 16 additions and 12 deletions

View file

@ -23,7 +23,7 @@ public partial class Cutscene : BaseState<PlayerState, CharacterBody3D>
base.EnterState();
MainObject.Show();
MainObject.Velocity = Vector3.Zero;
PlayerStorage.MovementDirection = Vector3.Zero;
PlayerStorage.MovementDirection = Vector2.Zero;
}
public override void ExitState()

View file

@ -1,6 +1,8 @@
using Cirno.Scripts.Components.Actors;
using Cirno.Scripts.Components.Actors._3D;
using Cirno.Scripts.Utils;
using Godot;
using GodotPlugins.Game;
namespace Cirno.Scripts.Components.FSM._3DPlayer;
@ -67,14 +69,16 @@ public partial class IsoMovementModule : ModuleBase<PlayerState, CharacterBody3D
var rotatedMovementDirection = movementInput.Rotated(Mathf.DegToRad(-45f));
PlayerStorage.MovementDirection = new Vector3(rotatedMovementDirection.X, 0, rotatedMovementDirection.Y);
//PlayerStorage.MovementDirection = new Vector3(rotatedMovementDirection.X, 0, rotatedMovementDirection.Y);
PlayerStorage.MovementDirection = rotatedMovementDirection;
HitboxSpriteProvider.SetVisibility(_isStrafing);
}
public override void PhysicsProcess(double delta)
{
var frameVelocity = MainObject.Velocity;
var frameVelocity = MainObject.Velocity.ToVector2();
var frameVelocityY = MainObject.Velocity.Y;
if (_isStrafing)
{
@ -83,25 +87,25 @@ public partial class IsoMovementModule : ModuleBase<PlayerState, CharacterBody3D
}
else
{
Vector3 targetVelocity = PlayerStorage.MovementDirection * Speed;
Vector2 targetVelocity = PlayerStorage.MovementDirection * Speed;
if (PlayerStorage.MovementDirection != Vector3.Zero)
if (PlayerStorage.MovementDirection != Vector2.Zero)
{
frameVelocity = frameVelocity.MoveToward(targetVelocity, Acceleration * (float)delta);
}
else
{
frameVelocity = frameVelocity.MoveToward(Vector3.Zero, Deceleration * (float)delta);
frameVelocity = frameVelocity.MoveToward(Vector2.Zero, Deceleration * (float)delta);
}
}
//MainObject.Velocity += _movementDirection * MovementSpeed;
var velocityY = Mathf.Clamp(frameVelocity.Y + Gravity * (float)delta, -FallSpeed, FallSpeed);
var velocityY = Mathf.Clamp(frameVelocityY + Gravity * (float)delta, -FallSpeed, FallSpeed);
frameVelocity.Y = velocityY;
//frameVelocity.Y = velocityY;
MainObject.Velocity = frameVelocity;
MainObject.Velocity = frameVelocity.ToVector3(velocityY);
MainObject.MoveAndSlide();
}

View file

@ -9,5 +9,5 @@ public partial class IsoPlayerStorageModule : Node
public Vector2 FacingDirection { get; set; } = Vector2.Down;
public Vector2 AimingDirection { get; set; } = Vector2.Down;
public Vector3 MovementDirection { get; set; } = Vector3.Zero;
public Vector2 MovementDirection { get; set; } = Vector2.Zero;
}