poprawki materialy unity 6, pajaki, podmiana katalogu FSM w AIControlerze, zmiana w Spider 2.0 Behaviours , skopane zycie bylo, ladowalo pajaka z zyciem 2.
This commit is contained in:
@@ -1,9 +1,33 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Invector.vCharacterController.AI
|
||||
{
|
||||
{
|
||||
public static class ProtectedMethodInvekerHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Invoke all method that contains the <see cref="vInitAIAttribute"/>
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="target"></param>
|
||||
public static void InvokeInitAI<T>(this T target) where T : vControlAI
|
||||
{
|
||||
var methods = target.GetType().GetMethods(BindingFlags.Instance | BindingFlags.NonPublic
|
||||
).Where(m => m.GetCustomAttributes(typeof(vInitAIAttribute), false).Length > 0)
|
||||
.ToArray();
|
||||
for (int i = 0; i < methods.Length; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
methods[i].Invoke(target, null);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
}
|
||||
[SelectionBase]
|
||||
[vClassHeader("AI BASIC CONTROLLER", iconName = "AI-icon")]
|
||||
public partial class vControlAI : vAIMotor, vIControlAI
|
||||
@@ -15,12 +39,12 @@ namespace Invector.vCharacterController.AI
|
||||
[vEditorToolbar("Agent", order = 5)]
|
||||
[SerializeField] protected bool useNavMeshAgent = true;
|
||||
[SerializeField] protected vAIUpdateQuality updatePathQuality = vAIUpdateQuality.Medium;
|
||||
[SerializeField] [Range(1f, 10f)] protected float aceleration = 8f;
|
||||
[SerializeField] [Range(0.05f, 10f)] protected float _stopingDistance = 0.2f;
|
||||
[SerializeField][Range(1f, 10f)] protected float aceleration = 8f;
|
||||
[SerializeField][Range(0.05f, 10f)] protected float _stopingDistance = 0.2f;
|
||||
[Header("Increase StoppingDistance by speed")]
|
||||
[SerializeField] [Range(0.05f, 10f)] protected float _walkingStopingDistance = 0.0f;
|
||||
[SerializeField] [Range(0.05f, 10f)] protected float _runningStopingDistance = 0.1f;
|
||||
[SerializeField] [Range(0.05f, 10f)] protected float _sprintingStopingDistance = 0.15f;
|
||||
[SerializeField][Range(0.05f, 10f)] protected float _walkingStopingDistance = 0.0f;
|
||||
[SerializeField][Range(0.05f, 10f)] protected float _runningStopingDistance = 0.1f;
|
||||
[SerializeField][Range(0.05f, 10f)] protected float _sprintingStopingDistance = 0.15f;
|
||||
|
||||
[vEditorToolbar("Waypoint", order = 6)]
|
||||
[vHelpBox("You can create a new WaypointArea at the Invector/AIController/Components/Create new WaypointArea", vHelpBoxAttribute.MessageType.Info)]
|
||||
@@ -43,14 +67,14 @@ namespace Invector.vCharacterController.AI
|
||||
[SerializeField] protected vAIUpdateQuality canseeTargetUpdateQuality = vAIUpdateQuality.Medium;
|
||||
[SerializeField, Tooltip("find target with current target found")] protected bool findOtherTarget = false;
|
||||
|
||||
[SerializeField][Range(1,100)] protected int maxTargetsDetection = 10;
|
||||
[SerializeField][Range(1, 100)] protected int maxTargetsDetection = 10;
|
||||
[SerializeField] protected float _changeTargetDelay = 2f;
|
||||
[SerializeField] protected bool findTargetByDistance = true;
|
||||
[SerializeField] protected float _fieldOfView = 90f;
|
||||
[SerializeField] protected float _minDistanceToDetect = 3f;
|
||||
[SerializeField] protected float _maxDistanceToDetect = 6f;
|
||||
[SerializeField] [vReadOnly] protected bool _hasPositionOfTheTarget;
|
||||
[SerializeField] [vReadOnly] protected bool _targetInLineOfSight;
|
||||
[SerializeField][vReadOnly] protected bool _hasPositionOfTheTarget;
|
||||
[SerializeField][vReadOnly] protected bool _targetInLineOfSight;
|
||||
[vHelpBox("Considerer maxDistanceToDetect value + lostTargetDistance", vHelpBoxAttribute.MessageType.None)]
|
||||
[SerializeField] protected float _lostTargetDistance = 4f;
|
||||
[SerializeField] protected float _timeToLostWithoutSight = 5f;
|
||||
@@ -59,25 +83,33 @@ namespace Invector.vCharacterController.AI
|
||||
[SerializeField] protected LayerMask _detectLayer;
|
||||
[SerializeField] protected vTagMask _detectTags;
|
||||
[SerializeField] protected LayerMask _obstacles = 1 << 0;
|
||||
[vEditorToolbar("Targets")]
|
||||
[vSeparator("Inside Range")]
|
||||
[SerializeField] protected List<vAITarget> targetsInRange = new List<vAITarget>();
|
||||
[vSeparator("Current")]
|
||||
[SerializeField] protected vAITarget _currentTarget;
|
||||
[vSeparator("Storage")]
|
||||
[SerializeField] protected List<vAITarget> _secundaryTargets = new List<vAITarget>();
|
||||
[vEditorToolbar("Debug")]
|
||||
[vHelpBox("Debug Options")]
|
||||
[SerializeField] protected bool _debugVisualDetection;
|
||||
[SerializeField] protected bool _debugRaySight;
|
||||
[SerializeField] protected bool _debugLastTargetPosition;
|
||||
[SerializeField] protected vAITarget _currentTarget;
|
||||
[SerializeField] protected vAIReceivedDamegeInfo _receivedDamage = new vAIReceivedDamegeInfo();
|
||||
internal vAIHeadtrack _headtrack;
|
||||
internal Collider[] targetsInRange;
|
||||
|
||||
|
||||
|
||||
internal vAIHeadtrack _headtrack;
|
||||
protected Collider[] targetsBuffer;
|
||||
|
||||
public List<vAITarget> secundaryTargets { get=> _secundaryTargets; set=> _secundaryTargets=value; }
|
||||
protected Vector3 _lastTargetPosition;
|
||||
protected int _currentWaypoint;
|
||||
|
||||
private float lostTargetTime;
|
||||
private Vector3 lastValidDestination;
|
||||
private UnityEngine.AI.NavMeshHit navHit;
|
||||
private float changeTargetTime;
|
||||
|
||||
protected float lostTargetTime;
|
||||
protected Vector3 lastValidDestination;
|
||||
protected UnityEngine.AI.NavMeshHit navHit;
|
||||
protected float changeTargetTime;
|
||||
|
||||
public virtual void CreatePrimaryComponents()
|
||||
{
|
||||
if (GetComponent<Rigidbody>() == null)
|
||||
@@ -109,6 +141,7 @@ namespace Invector.vCharacterController.AI
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected bool isWaypointStarted;
|
||||
#endregion
|
||||
|
||||
@@ -116,17 +149,16 @@ namespace Invector.vCharacterController.AI
|
||||
|
||||
protected Vector3 _destination;
|
||||
protected Vector3 lasDestination;
|
||||
protected Vector3 temporaryDirection;
|
||||
|
||||
[HideInInspector] public UnityEngine.AI.NavMeshAgent navMeshAgent;
|
||||
protected UnityEngine.AI.NavMeshHit navMeshHit;
|
||||
protected float updatePathTime;
|
||||
protected float updateFindTargetTime;
|
||||
protected float canseeTargetUpdateTime;
|
||||
protected float temporaryDirectionTime;
|
||||
protected float timeToResetOutDistance;
|
||||
protected float forceUpdatePathTime;
|
||||
protected bool isOutOfDistance;
|
||||
private int findAgentDestinationRadius;
|
||||
protected int findAgentDestinationRadius;
|
||||
#endregion
|
||||
|
||||
#region OVERRIDE METHODS. AI
|
||||
@@ -158,15 +190,7 @@ namespace Invector.vCharacterController.AI
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void Awake()
|
||||
{
|
||||
if (!animator)
|
||||
animator = GetComponent<Animator>();
|
||||
navMeshAgent = GetComponent<UnityEngine.AI.NavMeshAgent>();
|
||||
_headtrack = GetComponent<vAIHeadtrack>();
|
||||
}
|
||||
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
_receivedDamage = new vAIReceivedDamegeInfo();
|
||||
@@ -174,20 +198,21 @@ namespace Invector.vCharacterController.AI
|
||||
selfStartPosition = (!_selfStartingPoint && _customStartingPoint) ? _customStartingPoint.position : transform.position;
|
||||
_destination = transform.position;
|
||||
lasDestination = _destination;
|
||||
//navMeshAgent = GetComponent<UnityEngine.AI.NavMeshAgent>();
|
||||
navMeshAgent = GetComponent<UnityEngine.AI.NavMeshAgent>();
|
||||
if (!navMeshAgent) return;
|
||||
navMeshAgent.updatePosition = false;
|
||||
navMeshAgent.updateRotation = false;
|
||||
if (isOnNavMesh) navMeshAgent.enabled = true;
|
||||
RotateTo(transform.forward);
|
||||
|
||||
if (currentTarget != null) currentTarget.InitTarget(currentTarget.transform);
|
||||
//_headtrack = GetComponent<vAIHeadtrack>();
|
||||
targetsInRange = new Collider[maxTargetsDetection];
|
||||
if (currentTarget.transform != null) currentTarget.InitTarget(currentTarget.transform);
|
||||
_headtrack = GetComponent<vAIHeadtrack>();
|
||||
targetsBuffer = new Collider[maxTargetsDetection];
|
||||
base.Start();
|
||||
aiComponents = new Dictionary<System.Type, vIAIComponent>();
|
||||
|
||||
var _aiComponents = GetComponents<vIAIComponent>();
|
||||
|
||||
|
||||
for (int i = 0; i < _aiComponents.Length; i++)
|
||||
{
|
||||
if (!aiComponents.ContainsKey(_aiComponents[i].ComponentType))
|
||||
@@ -196,6 +221,8 @@ namespace Invector.vCharacterController.AI
|
||||
}
|
||||
}
|
||||
StartCoroutine(AlignDetectionPoint());
|
||||
|
||||
this.InvokeInitAI();
|
||||
}
|
||||
|
||||
protected virtual IEnumerator AlignDetectionPoint()
|
||||
@@ -397,13 +424,13 @@ namespace Invector.vCharacterController.AI
|
||||
if (isDead || isJumping) return;
|
||||
|
||||
if (useNavMeshAgent && navMeshAgent)
|
||||
{
|
||||
{
|
||||
ControlNavMeshAgent();
|
||||
UpdateAgentPath();
|
||||
}
|
||||
|
||||
bool forceMovement = !navMeshAgent.hasPath && remainingDistanceWithoutAgent > navMeshAgent.stoppingDistance + _capsuleCollider.radius;
|
||||
var dir = !forceMovement && navMeshAgent != null && navMeshAgent.enabled && useNavMeshAgent ? navMeshAgent.desiredVelocity * (!isInDestination ? 1 : 0) :
|
||||
var dir = !forceMovement && navMeshAgent != null && navMeshAgent.enabled && useNavMeshAgent ? desiredVelocity * (!isInDestination ? 1 : 0) :
|
||||
((new Vector3(destination.x, transform.position.y, destination.z) - transform.position).normalized * Mathf.Clamp(remainingDistanceWithoutAgent - stopingDistance, 0, 1f));
|
||||
//Convert Direction to Input
|
||||
var movementInput = transform.InverseTransformDirection(dir);
|
||||
@@ -420,21 +447,18 @@ namespace Invector.vCharacterController.AI
|
||||
|
||||
if (movementInput.magnitude > 0.1f)
|
||||
{
|
||||
|
||||
|
||||
if (temporaryDirectionTime <= 0 && isStrafing == false)
|
||||
SetMovementInput(movementInput, aceleration);
|
||||
else
|
||||
SetMovementInput(movementInput, temporaryDirectionTime <= 0 ? transform.forward : temporaryDirection, aceleration);
|
||||
}
|
||||
else if (temporaryDirectionTime > 0 && temporaryDirection.magnitude >= 0.1f && movementInput.magnitude < 0.1f)
|
||||
{
|
||||
input = Vector3.zero;
|
||||
}
|
||||
else input = Vector3.zero;
|
||||
if (!isGrounded || isJumping || isRolling) navMeshAgent.enabled = false;
|
||||
temporaryDirectionTime -= Time.deltaTime;
|
||||
}
|
||||
|
||||
public virtual Vector3 desiredVelocity => navMeshAgent.desiredVelocity;
|
||||
|
||||
protected virtual void CheckAgentDistanceFromAI()
|
||||
{
|
||||
if (!useNavMeshAgent || !navMeshAgent || !navMeshAgent.enabled) return;
|
||||
@@ -457,7 +481,6 @@ namespace Invector.vCharacterController.AI
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void ControlNavMeshAgent()
|
||||
{
|
||||
if (isDead) return;
|
||||
@@ -474,7 +497,7 @@ namespace Invector.vCharacterController.AI
|
||||
if (navMeshAgent.enabled && isOnJumpLink && !isJumping && isGrounded)
|
||||
{
|
||||
var jumpDir = navMeshAgent.currentOffMeshLinkData.endPos - transform.position;
|
||||
var jumpTarget = transform.position+jumpDir.normalized*(jumpDir.magnitude+stopingDistance);
|
||||
var jumpTarget = transform.position + jumpDir.normalized * (jumpDir.magnitude + stopingDistance);
|
||||
JumpTo(jumpTarget);
|
||||
}
|
||||
|
||||
@@ -593,6 +616,7 @@ namespace Invector.vCharacterController.AI
|
||||
_hasPositionOfTheTarget = false;
|
||||
}
|
||||
HandleLostTarget();
|
||||
HandleTargetsInRange();
|
||||
canseeTargetUpdateTime = GetUpdateTimeFromQuality(canseeTargetUpdateQuality);
|
||||
}
|
||||
|
||||
@@ -600,20 +624,43 @@ namespace Invector.vCharacterController.AI
|
||||
{
|
||||
if (currentTarget != null && currentTarget.transform != null)
|
||||
{
|
||||
if (currentTarget.hasHealthController && (currentTarget.isDead || targetDistance > (_maxDistanceToDetect + _lostTargetDistance) || (!targetInLineOfSight && !_hasPositionOfTheTarget)))
|
||||
if ((currentTarget.isDead || targetDistance > (_maxDistanceToDetect + _lostTargetDistance) || (!targetInLineOfSight && !_hasPositionOfTheTarget)))
|
||||
{
|
||||
if (currentTarget.isFixedTarget)
|
||||
currentTarget.isLost = true;
|
||||
else
|
||||
currentTarget.ClearTarget();
|
||||
}
|
||||
else if (!currentTarget.hasHealthController && (currentTarget.transform == null || !currentTarget.transform.gameObject.activeSelf || targetDistance > (_maxDistanceToDetect + _lostTargetDistance) || (!targetInLineOfSight && !_hasPositionOfTheTarget)))
|
||||
else if ((currentTarget.transform == null || !currentTarget.transform.gameObject.activeSelf || targetDistance > (_maxDistanceToDetect + _lostTargetDistance) || (!targetInLineOfSight && !_hasPositionOfTheTarget)))
|
||||
{
|
||||
if (currentTarget.isFixedTarget)
|
||||
currentTarget.isLost = true;
|
||||
else
|
||||
currentTarget.ClearTarget();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void HandleTargetsInRange()
|
||||
{
|
||||
for (int i = 0; i < targetsInRange.Count; i++)
|
||||
{
|
||||
var t = targetsInRange[i];
|
||||
if (t.transform)
|
||||
{
|
||||
if (t.transform == currentTarget.transform) _currentTarget=t;
|
||||
var distance = Vector3.Distance(t.transform.position, transform.position);
|
||||
if (distance > _maxDistanceToDetect + _lostTargetDistance)
|
||||
{
|
||||
targetsInRange.RemoveAt(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
targetsInRange.RemoveAt(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -690,6 +737,11 @@ namespace Invector.vCharacterController.AI
|
||||
}
|
||||
}
|
||||
|
||||
public virtual List<vAITarget> GetTargetsInRange()
|
||||
{
|
||||
return targetsInRange;
|
||||
}
|
||||
|
||||
public virtual void FindTarget()
|
||||
{
|
||||
FindSpecificTarget(_detectTags, _detectLayer, true);
|
||||
@@ -703,33 +755,48 @@ namespace Invector.vCharacterController.AI
|
||||
public virtual void FindSpecificTarget(List<string> m_detectTags, LayerMask m_detectLayer, bool checkForObstables = true)
|
||||
{
|
||||
if (updateFindTargetTime > Time.time) return;
|
||||
updateFindTargetTime = Time.time + GetUpdateTimeFromQuality(findTargetUpdateQuality);
|
||||
if (!findOtherTarget && currentTarget.transform) return;
|
||||
if (currentTarget.transform && currentTarget.isFixedTarget && !findOtherTarget) return;
|
||||
int targetsCount = Physics.OverlapSphereNonAlloc(transform.position + transform.up, _maxDistanceToDetect, targetsInRange, m_detectLayer);
|
||||
updateFindTargetTime = Time.time + GetUpdateTimeFromQuality(findTargetUpdateQuality);
|
||||
|
||||
int targetsCount = Physics.OverlapSphereNonAlloc(transform.position + transform.up, _maxDistanceToDetect, targetsBuffer, m_detectLayer);
|
||||
|
||||
if (targetsCount > 0)
|
||||
{
|
||||
|
||||
Transform target = currentTarget != null && _hasPositionOfTheTarget ? currentTarget.transform : null;
|
||||
var _targetDistance = target && targetInLineOfSight ? targetDistance : Mathf.Infinity;
|
||||
|
||||
bool targetFound = false;
|
||||
for (int i = 0; i < targetsCount; i++)
|
||||
{
|
||||
if (targetsInRange[i] != null && targetsInRange[i].transform != transform && m_detectTags.Contains(targetsInRange[i].gameObject.tag) && (!checkForObstables || CheckCanSeeTarget(targetsInRange[i])))
|
||||
if (targetsBuffer[i] != null && targetsBuffer[i].transform != transform && m_detectTags.Contains(targetsBuffer[i].gameObject.tag))
|
||||
{
|
||||
if (findTargetByDistance)
|
||||
///Add new target in range
|
||||
if(!targetsInRange.Exists(t=>t.transform == targetsBuffer[i].transform))
|
||||
{
|
||||
var newTargetDistance = Vector3.Distance(targetsInRange[i].transform.position, transform.position);
|
||||
|
||||
if (newTargetDistance < _targetDistance)
|
||||
{
|
||||
target = targetsInRange[i].transform;
|
||||
_targetDistance = newTargetDistance;
|
||||
}
|
||||
vAITarget t = new vAITarget(targetsBuffer[i].transform);
|
||||
|
||||
if(t.isDead==false) targetsInRange.Add(new vAITarget(targetsBuffer[i]));
|
||||
}
|
||||
else
|
||||
if (!findOtherTarget && currentTarget.transform) continue;
|
||||
if (currentTarget.transform && currentTarget.isFixedTarget && !findOtherTarget) continue;
|
||||
///Store new target
|
||||
if ( (findTargetByDistance || !targetFound) && (!checkForObstables || CheckCanSeeTarget(targetsBuffer[i])))
|
||||
{
|
||||
target = targetsInRange[i].transform;
|
||||
break;
|
||||
if (findTargetByDistance)
|
||||
{
|
||||
var newTargetDistance = Vector3.Distance(targetsBuffer[i].transform.position, transform.position);
|
||||
|
||||
if (newTargetDistance < _targetDistance)
|
||||
{
|
||||
target = targetsBuffer[i].transform;
|
||||
targetFound = true;
|
||||
_targetDistance = newTargetDistance;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
targetFound = true;
|
||||
target = targetsBuffer[i].transform;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -737,34 +804,28 @@ namespace Invector.vCharacterController.AI
|
||||
if (currentTarget == null || target != null && target != currentTarget.transform)
|
||||
{
|
||||
if (target != null)
|
||||
SetCurrentTarget(target);
|
||||
SetCurrentTarget(targetsInRange.Find(t=>t==target));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public virtual bool TryGetTarget(out vAITarget target)
|
||||
{
|
||||
return TryGetTarget(_detectTags, out target);
|
||||
}
|
||||
|
||||
public virtual bool TryGetTarget(string tag,out vAITarget target)
|
||||
public virtual bool TryGetTarget(string tag, out vAITarget target)
|
||||
{
|
||||
Collider[] ts = System.Array.FindAll(targetsInRange, c => c != null && c.gameObject.CompareTag(tag));
|
||||
if(ts!=null && ts.Length>1)
|
||||
var ts = targetsInRange.FindAll(c => c != null && c.transform!=null && c.transform.gameObject.CompareTag(tag));
|
||||
if (ts != null && ts.Count > 1)
|
||||
{
|
||||
System.Array.Sort(ts, delegate (Collider a, Collider b)
|
||||
{
|
||||
return Vector2.Distance(this.transform.position, a.transform.position)
|
||||
.CompareTo(
|
||||
Vector2.Distance(this.transform.position, b.transform.position));
|
||||
});
|
||||
ts= ts.OrderBy(t => Vector3.Distance(t.transform.position, transform.position)).ToList();
|
||||
}
|
||||
|
||||
if (ts != null && ts.Length > 0)
|
||||
|
||||
if (ts != null && ts.Count > 0)
|
||||
{
|
||||
target = new vAITarget();
|
||||
target.InitTarget(ts[0].transform);
|
||||
target = ts[0];
|
||||
return true;
|
||||
}
|
||||
target = null;
|
||||
@@ -773,21 +834,16 @@ namespace Invector.vCharacterController.AI
|
||||
|
||||
public virtual bool TryGetTarget(List<string> detectTags, out vAITarget target)
|
||||
{
|
||||
Collider[] ts = System.Array.FindAll(targetsInRange, c => c!=null && detectTags.Contains(c.gameObject.tag));
|
||||
if (ts != null && ts.Length > 1)
|
||||
var ts = targetsInRange.FindAll(c => c != null && c.transform != null && detectTags.Contains(c.transform.gameObject.tag));
|
||||
|
||||
if (ts != null && ts.Count > 1)
|
||||
{
|
||||
System.Array.Sort(ts, delegate (Collider a, Collider b)
|
||||
{
|
||||
return Vector2.Distance(this.transform.position, a.transform.position)
|
||||
.CompareTo(
|
||||
Vector2.Distance(this.transform.position, b.transform.position));
|
||||
});
|
||||
ts = ts.OrderBy(t => Vector3.Distance(t.transform.position, transform.position)).ToList();
|
||||
}
|
||||
|
||||
if (ts != null && ts.Length > 0)
|
||||
if (ts != null && ts.Count > 0)
|
||||
{
|
||||
target = new vAITarget();
|
||||
target.InitTarget(ts[0].transform);
|
||||
target = ts[0];
|
||||
return true;
|
||||
}
|
||||
target = null;
|
||||
@@ -796,26 +852,43 @@ namespace Invector.vCharacterController.AI
|
||||
|
||||
public virtual void SetCurrentTarget(Transform target)
|
||||
{
|
||||
SetCurrentTarget(target, true);
|
||||
SetCurrentTarget(target, false);
|
||||
}
|
||||
public virtual void SetCurrentTarget(vAITarget target)
|
||||
{
|
||||
SetCurrentTarget(target, false);
|
||||
}
|
||||
|
||||
public virtual void SetCurrentTarget(Transform target, bool overrideCanseTarget)
|
||||
{
|
||||
if (changeTargetTime < Time.time)
|
||||
if (target == null) return;
|
||||
changeTargetTime = _changeTargetDelay + Time.time;
|
||||
currentTarget.InitTarget(target);
|
||||
if (overrideCanseTarget)
|
||||
{
|
||||
changeTargetTime = _changeTargetDelay + Time.time;
|
||||
currentTarget.InitTarget(target);
|
||||
if (overrideCanseTarget)
|
||||
{
|
||||
currentTarget.isLost = false;
|
||||
_targetInLineOfSight = true;
|
||||
_hasPositionOfTheTarget = false;
|
||||
}
|
||||
updateFindTargetTime = 0f;
|
||||
updatePathTime = 0f;
|
||||
lastTargetPosition = target.position;
|
||||
LookToTarget(target, 2);
|
||||
currentTarget.isLost = false;
|
||||
_targetInLineOfSight = true;
|
||||
_hasPositionOfTheTarget = true;
|
||||
}
|
||||
updateFindTargetTime = 0f;
|
||||
updatePathTime = 0f;
|
||||
lastTargetPosition = target.position;
|
||||
LookToTarget(target, 2);
|
||||
}
|
||||
public virtual void SetCurrentTarget(vAITarget target, bool overrideCanseTarget)
|
||||
{
|
||||
if (target.transform == null) return;
|
||||
changeTargetTime = _changeTargetDelay + Time.time;
|
||||
currentTarget = target;
|
||||
if (overrideCanseTarget)
|
||||
{
|
||||
currentTarget.isLost = false;
|
||||
_targetInLineOfSight = true;
|
||||
_hasPositionOfTheTarget = true;
|
||||
}
|
||||
updateFindTargetTime = 0f;
|
||||
updatePathTime = 0f;
|
||||
lastTargetPosition = target.transform.position;
|
||||
LookToTarget(target, 2);
|
||||
}
|
||||
|
||||
public virtual void RemoveCurrentTarget()
|
||||
@@ -837,7 +910,7 @@ namespace Invector.vCharacterController.AI
|
||||
{
|
||||
if (_headtrack) _headtrack.LookAtTarget(target, stayLookTime, offsetLookHeight);
|
||||
}
|
||||
|
||||
|
||||
public virtual void SetSpeed(vAIMovementSpeed movementSpeed)
|
||||
{
|
||||
if (this.movementSpeed != movementSpeed)
|
||||
@@ -855,7 +928,7 @@ namespace Invector.vCharacterController.AI
|
||||
{
|
||||
get
|
||||
{
|
||||
if (useNavMeshAgent && (remainingDistance <= stopingDistance || navMeshAgent.hasPath && remainingDistance > stopingDistance && navMeshAgent.desiredVelocity.magnitude < 0.1f)) return true;
|
||||
if (useNavMeshAgent && (remainingDistance <= stopingDistance || navMeshAgent.hasPath && remainingDistance > stopingDistance && desiredVelocity.magnitude < 0.1f)) return true;
|
||||
return remainingDistance <= stopingDistance;
|
||||
}
|
||||
}
|
||||
@@ -921,7 +994,7 @@ namespace Invector.vCharacterController.AI
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public virtual void MoveTo(Vector3 newDestination, vAIMovementSpeed speed = vAIMovementSpeed.Walking)
|
||||
{
|
||||
if (isStrafing) updatePathTime = 0;
|
||||
@@ -931,7 +1004,7 @@ namespace Invector.vCharacterController.AI
|
||||
dir.y = 0;
|
||||
this.destination = newDestination;
|
||||
temporaryDirection = transform.forward;
|
||||
|
||||
|
||||
temporaryDirectionTime = 0;
|
||||
}
|
||||
|
||||
@@ -944,14 +1017,21 @@ namespace Invector.vCharacterController.AI
|
||||
temporaryDirection = targetDirection;
|
||||
temporaryDirectionTime = 2f;
|
||||
}
|
||||
|
||||
|
||||
public virtual void StrafeMoveTo(Vector3 newDestination, vAIMovementSpeed speed = vAIMovementSpeed.Walking)
|
||||
{
|
||||
if (useNavMeshAgent && navMeshAgent && navMeshAgent.isOnNavMesh && navMeshAgent.isStopped) navMeshAgent.isStopped = false;
|
||||
SetStrafeLocomotion();
|
||||
SetSpeed(speed);
|
||||
destination = newDestination;
|
||||
}
|
||||
|
||||
public virtual void RotateTo(Vector3 targetDirection)
|
||||
{
|
||||
|
||||
targetDirection.y = 0;
|
||||
if (Vector3.Angle(transform.forward, targetDirection) > 20)
|
||||
{
|
||||
|
||||
temporaryDirection = targetDirection;
|
||||
temporaryDirectionTime = 2f;
|
||||
}
|
||||
@@ -1015,7 +1095,6 @@ namespace Invector.vCharacterController.AI
|
||||
return customStartPoint ? _customStartingPoint.position : transform.position;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void NextWayPoint()
|
||||
{
|
||||
targetWaypoint = GetWaypoint();
|
||||
@@ -1049,6 +1128,7 @@ namespace Invector.vCharacterController.AI
|
||||
|
||||
public virtual bool HasComponent<T>() where T : vIAIComponent
|
||||
{
|
||||
if (aiComponents == null) return false;
|
||||
return aiComponents.ContainsKey(typeof(T));
|
||||
}
|
||||
|
||||
@@ -1057,9 +1137,59 @@ namespace Invector.vCharacterController.AI
|
||||
return aiComponents.ContainsKey(typeof(T)) ? (T)aiComponents[typeof(T)] : default(T);
|
||||
}
|
||||
|
||||
protected List<Collider> triggers = new List<Collider>();
|
||||
|
||||
float checkTriggerFrequency;
|
||||
|
||||
protected override void OnTriggerEnter(Collider other)
|
||||
{
|
||||
base.OnTriggerEnter(other);
|
||||
if (!triggers.Contains(other)) triggers.Add(other);
|
||||
}
|
||||
|
||||
protected override void OnTriggerExit(Collider other)
|
||||
{
|
||||
if (triggers.Contains(other)) triggers.Remove(other);
|
||||
}
|
||||
|
||||
protected override void OnTriggerStay(Collider other)
|
||||
{
|
||||
base.OnTriggerStay(other);
|
||||
|
||||
if (checkTriggerFrequency < Time.time)
|
||||
{
|
||||
triggers = triggers.FindAll(c => c != null);
|
||||
checkTriggerFrequency = Time.time + 2f;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsInTriggerWithTag(string tag)
|
||||
{
|
||||
return triggers.Exists(c => c != null && c.gameObject.CompareTag(tag));
|
||||
}
|
||||
|
||||
public bool IsInTriggerWithName(string name)
|
||||
{
|
||||
return triggers.Exists(c => c != null && c.gameObject.name.Equals(name));
|
||||
}
|
||||
|
||||
public bool IsInTriggerWithTag(string tag, out Collider result)
|
||||
{
|
||||
var _c = triggers.Find(c => c != null && c.gameObject.CompareTag(tag));
|
||||
result = _c;
|
||||
return _c != null;
|
||||
}
|
||||
|
||||
public bool IsInTriggerWithName(string name, out Collider result)
|
||||
{
|
||||
var _c = triggers.Find(c => c != null && c.gameObject.name.Equals(name));
|
||||
result = _c;
|
||||
return _c != null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user