mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 08:45:33 +00:00
Better gravity handling
This commit is contained in:
parent
d01ab303fc
commit
16992c2bea
4 changed files with 16 additions and 12 deletions
|
|
@ -283,8 +283,8 @@ Speed = 5
|
|||
StrafeSpeed = 2
|
||||
Acceleration = 150.0
|
||||
Deceleration = 20.0
|
||||
Gravity = -50.0
|
||||
FallSpeed = 100.0
|
||||
Gravity = -20.0
|
||||
FallSpeed = 2.0
|
||||
|
||||
[node name="Storage" type="Node" parent="." node_paths=PackedStringArray("Root")]
|
||||
script = ExtResource("6_habpy")
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue