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:
parent
90286368b6
commit
8565545154
2 changed files with 19 additions and 4 deletions
Assets/Scripts/Behaviours/PedAI
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue