2
0
Fork 0
mirror of https://github.com/GTA-ASM/SanAndreasUnity synced 2025-03-02 22:27:18 +00:00

prevent flickering when chasing target

This commit is contained in:
in0finite 2021-10-10 19:45:34 +02:00
parent 90286368b6
commit 8565545154
2 changed files with 19 additions and 4 deletions
Assets/Scripts/Behaviours/PedAI

View file

@ -8,11 +8,15 @@ namespace SanAndreasUnity.Behaviours.Peds.AI
{
public Ped TargetPed { get; private set; }
private bool _wasInRange = false;
public override void OnBecameActive()
{
base.OnBecameActive();
_wasInRange = false;
this.TargetPed = this.ParameterForEnteringState as Ped;
if (this.TargetPed != null)
_enemyPeds.AddIfNotPresent(this.TargetPed);
@ -30,7 +34,7 @@ namespace SanAndreasUnity.Behaviours.Peds.AI
return;
}
this.UpdateAttackOnPed(this.TargetPed);
this.UpdateAttackOnPed(this.TargetPed, ref _wasInRange);
}
public Ped GetNextPedToAttack()
@ -50,7 +54,7 @@ namespace SanAndreasUnity.Behaviours.Peds.AI
return closestPed;
}
public void UpdateAttackOnPed(Ped ped)
public void UpdateAttackOnPed(Ped ped, ref bool wasInRange)
{
//var weapon = this.MyPed.CurrentWeapon;
Vector3 myHeadPos = GetHeadOrTransform(this.MyPed).position;
@ -80,8 +84,13 @@ namespace SanAndreasUnity.Behaviours.Peds.AI
}
else
{
if (diff.magnitude < 10f)
float rangeRequired = wasInRange ? 10f : 8f;
wasInRange = false;
if (diff.magnitude < rangeRequired)
{
wasInRange = true;
this.MyPed.AimDirection = aimDir;
this.MyPed.IsAimOn = true;
this.MyPed.IsFireOn = true;

View file

@ -11,6 +11,8 @@ namespace SanAndreasUnity.Behaviours.Peds.AI
private Ped _currentlyEngagedPed;
private bool _wasInRange = false;
private ChaseState _chaseState;
@ -25,6 +27,7 @@ namespace SanAndreasUnity.Behaviours.Peds.AI
{
base.OnBecameActive();
_wasInRange = false;
this.TargetPed = this.ParameterForEnteringState as Ped;
}
@ -49,11 +52,14 @@ namespace SanAndreasUnity.Behaviours.Peds.AI
this.UpdateFollowing_MovementPart();
if (null == _currentlyEngagedPed)
{
_currentlyEngagedPed = _chaseState.GetNextPedToAttack();
_wasInRange = false;
}
if (_currentlyEngagedPed != null)
{
_chaseState.UpdateAttackOnPed(_currentlyEngagedPed);
_chaseState.UpdateAttackOnPed(_currentlyEngagedPed, ref _wasInRange);
}
else
{