mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 10:35:34 +00:00
Enemy Gravity
This commit is contained in:
parent
b3bfc1a888
commit
d1517f864a
9 changed files with 65 additions and 9 deletions
|
|
@ -11,6 +11,7 @@ public partial class Alert : EnemyStateBase3D
|
|||
[Export] public EnemyStorage3D Storage { get; private set; }
|
||||
[Export] public PlayerDetection3D PlayerDetection { get; private set; }
|
||||
[Export] public NavigationProvider3D NavigationModule { get; private set; }
|
||||
[Export] public GravityProvider GravityProvider { get; private set; }
|
||||
[Export] public bool DebugEnabled { get; set; } = false;
|
||||
|
||||
private bool _isPlayerInRange = false;
|
||||
|
|
@ -79,6 +80,12 @@ public partial class Alert : EnemyStateBase3D
|
|||
|
||||
NavigationModule.Move(Storage.EnemyData.MovementSpeed);
|
||||
|
||||
// Calculate gravity
|
||||
|
||||
MainObject.Velocity = new Vector3(MainObject.Velocity.X, GravityProvider.CalculateGravityVelocity(MainObject.Velocity.Y, delta), MainObject.Velocity.Z);
|
||||
|
||||
MainObject.MoveAndSlide();
|
||||
|
||||
//Storage.FacingDirection = MainObject.Velocity.SnapToCardinal().Normalized();
|
||||
Storage.FacingDirection = MainObject.Velocity.ToVector2().Normalized();
|
||||
Storage.AimingDirection = Storage.FacingDirection;
|
||||
|
|
|
|||
16
Scripts/Components/FSM/Enemy/3D/GravityProvider.cs
Normal file
16
Scripts/Components/FSM/Enemy/3D/GravityProvider.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.FSM.Enemy._3D;
|
||||
|
||||
public partial class GravityProvider : Node
|
||||
{
|
||||
[Export] public float Gravity = -9.8f;
|
||||
[Export] public float MaxFallSpeed = 20f;
|
||||
|
||||
public float CalculateGravityVelocity(float frameVelocityY, double delta)
|
||||
{
|
||||
var velocityY = Mathf.Clamp(frameVelocityY + Gravity * (float)delta, -MaxFallSpeed, MaxFallSpeed);
|
||||
|
||||
return velocityY;
|
||||
}
|
||||
}
|
||||
1
Scripts/Components/FSM/Enemy/3D/GravityProvider.cs.uid
Normal file
1
Scripts/Components/FSM/Enemy/3D/GravityProvider.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://qrdor3gk6x37
|
||||
|
|
@ -10,6 +10,8 @@ public partial class Idle : EnemyStateBase3D
|
|||
[Export] public EnemyStorage3D Storage { get; private set; }
|
||||
[Export] public PlayerDetection3D PlayerDetection { get; private set; }
|
||||
|
||||
[Export] public GravityProvider GravityProvider { get; private set; }
|
||||
|
||||
[Export] public bool DebugEnabled { get; set; } = false;
|
||||
|
||||
private bool _isPlayerInRange = false;
|
||||
|
|
@ -84,6 +86,10 @@ public partial class Idle : EnemyStateBase3D
|
|||
DebugDraw3D.DrawText(MainObject.GlobalPosition - new Vector3(0,16,0), "Idle");
|
||||
|
||||
}
|
||||
|
||||
MainObject.Velocity = new Vector3(MainObject.Velocity.X, GravityProvider.CalculateGravityVelocity(MainObject.Velocity.Y, delta), MainObject.Velocity.Z);
|
||||
|
||||
MainObject.MoveAndSlide();
|
||||
}
|
||||
|
||||
public override void ProcessState(double delta)
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public partial class Init : EnemyStateBase3D
|
|||
//DamageReceiver.HealthProvider.MaxResource = StorageModule.Root.EnemyResource.MaxHealth;
|
||||
DetectionProvider.Initialize(MainObject);
|
||||
Storage.AiState = Storage.Root.StartingAiState;
|
||||
|
||||
|
||||
Storage.HomePosition = MainObject.GlobalPosition;
|
||||
// TODO: Hide wings
|
||||
// TODO: Hide aiming reticule
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ public partial class NavigationProvider3D : Node
|
|||
_on_navigation_agent_3d_velocity_computed(newVelocity);
|
||||
}
|
||||
|
||||
_characterBody.MoveAndSlide();
|
||||
|
||||
}
|
||||
|
||||
public void _on_navigation_agent_3d_velocity_computed(Vector3 safeVelocity)
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ public partial class Shooting : EnemyStateBase3D
|
|||
[Export] public Weapon3D EquippedWeapon;
|
||||
[Export] public NavigationProvider3D NavigationModule { get; private set; }
|
||||
|
||||
[Export] public GravityProvider GravityProvider { get; private set; }
|
||||
|
||||
private bool _isPlayerInRange = false;
|
||||
private Vector3? _currentStrafeTarget = null;
|
||||
private float _strafeSpeed => Storage.EnemyData.StrafeSpeed;
|
||||
|
|
@ -99,6 +101,11 @@ public partial class Shooting : EnemyStateBase3D
|
|||
NavigationModule.SetTarget(_currentStrafeTarget.Value);
|
||||
NavigationModule.Move(_strafeSpeed);
|
||||
}
|
||||
|
||||
// Calculate gravity
|
||||
MainObject.Velocity = new Vector3(MainObject.Velocity.X, GravityProvider.CalculateGravityVelocity(MainObject.Velocity.Y, delta), MainObject.Velocity.Z);
|
||||
|
||||
MainObject.MoveAndSlide();
|
||||
}
|
||||
|
||||
private Vector3? CalculateStrafePosition()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue