mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-06 09:35:53 +00:00
Grahpics overhaul and predicting bullets
This commit is contained in:
parent
24386e724f
commit
946e7df71e
14 changed files with 144 additions and 26 deletions
|
|
@ -16,6 +16,7 @@ public partial class PlayerDetectionModule : Area2D
|
|||
public uint ObstaclesCollisionMask { get; private set; }
|
||||
|
||||
public Vector2? LastKnownPlayerPosition { get; set; }
|
||||
public Vector2? LastKnowPlayerVelocity { get; set; }
|
||||
|
||||
//public bool PlayerInActiveArea { get; private set; }
|
||||
private CollisionShape2D _collisionShape2D;
|
||||
|
|
@ -77,6 +78,7 @@ public partial class PlayerDetectionModule : Area2D
|
|||
if (found)
|
||||
{
|
||||
LastKnownPlayerPosition = GameManager.Instance.PlayerPosition;
|
||||
LastKnowPlayerVelocity = GameManager.Instance.PlayerVelocity;
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using Cirno.Scripts.Components.Actors;
|
||||
using Cirno.Scripts.Enums;
|
||||
using Cirno.Scripts.Utils;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.FSM.Enemy;
|
||||
|
|
@ -150,13 +151,27 @@ public partial class Shooting : EnemyStateBase
|
|||
|
||||
return null; // No valid strafe position found
|
||||
}
|
||||
|
||||
private Vector2 GetShootDirection()
|
||||
{
|
||||
if (StorageModule.EnemyData.PredictPlayer && PlayerDetection.LastKnowPlayerVelocity.HasValue)
|
||||
{
|
||||
var predictedDirection = MathFunctions.PredictInterceptPosition(MainObject.GlobalPosition,
|
||||
PlayerDetection.LastKnownPlayerPosition.Value, PlayerDetection.LastKnowPlayerVelocity.Value,
|
||||
EquippedWeapon.WeaponData.BulletData.BulletSpeed);
|
||||
if (predictedDirection.HasValue) return (predictedDirection.Value - MainObject.GlobalPosition).Normalized();
|
||||
|
||||
}
|
||||
|
||||
return ( PlayerDetection.LastKnownPlayerPosition.Value - MainObject.GlobalPosition).Normalized();
|
||||
}
|
||||
|
||||
private void Shoot()
|
||||
{
|
||||
if (EquippedWeapon == null) return;
|
||||
if (!PlayerDetection.LastKnownPlayerPosition.HasValue) return;
|
||||
|
||||
var direction = ( PlayerDetection.LastKnownPlayerPosition.Value - MainObject.GlobalPosition).Normalized();
|
||||
var direction = GetShootDirection();
|
||||
|
||||
// Shoot at the player's last known position
|
||||
EquippedWeapon.ShootDirection = direction;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue