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:
@@ -9,3 +9,10 @@ MonoImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 123618
|
||||
packageName: Invector FSM AI Template
|
||||
packageVersion: 1.1.9a
|
||||
assetPath: Assets/Invector-FSMAIController/Scripts/AI/AI Controllers/Editor/vAIShooterManagerEditor.cs
|
||||
uploadId: 601882
|
||||
|
||||
@@ -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
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,3 +10,10 @@ MonoImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 123618
|
||||
packageName: Invector FSM AI Template
|
||||
packageVersion: 1.1.9a
|
||||
assetPath: Assets/Invector-FSMAIController/Scripts/AI/AI Controllers/vControlAI.cs
|
||||
uploadId: 601882
|
||||
|
||||
@@ -10,3 +10,10 @@ MonoImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 123618
|
||||
packageName: Invector FSM AI Template
|
||||
packageVersion: 1.1.9a
|
||||
assetPath: Assets/Invector-FSMAIController/Scripts/AI/AI Controllers/vControlAICombat.cs
|
||||
uploadId: 601882
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
|
||||
using Invector.vEventSystems;
|
||||
using Invector.vEventSystems;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
namespace Invector.vCharacterController.AI
|
||||
@@ -9,10 +8,10 @@ namespace Invector.vCharacterController.AI
|
||||
{
|
||||
public vMelee.vMeleeManager MeleeManager { get; set; }
|
||||
public bool isEquipping { get; protected set; }
|
||||
private int _moveSetID;
|
||||
private int _attackID;
|
||||
private int _defenceID;
|
||||
private int _recoilID;
|
||||
protected int _moveSetID;
|
||||
protected int _attackID;
|
||||
protected int _defenseID;
|
||||
protected int _recoilID;
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
@@ -58,18 +57,18 @@ namespace Invector.vCharacterController.AI
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual int defenceID
|
||||
protected virtual int defenseID
|
||||
{
|
||||
get
|
||||
{
|
||||
return _defenceID;
|
||||
return _defenseID;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value != _defenceID)
|
||||
if (value != _defenseID)
|
||||
{
|
||||
_defenceID = value;
|
||||
animator.SetInteger("DefenseID", _defenceID);
|
||||
_defenseID = value;
|
||||
animator.SetInteger("DefenseID", _defenseID);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -83,7 +82,7 @@ namespace Invector.vCharacterController.AI
|
||||
if (MeleeManager) MeleeManager.hitProperties.hitDamageTags = tags;
|
||||
}
|
||||
|
||||
public override void Attack(bool strongAttack = false, int _newAttackID = -1,bool forceCanAttack = false)
|
||||
public override void Attack(bool strongAttack = false, int _newAttackID = -1, bool forceCanAttack = false)
|
||||
{
|
||||
if (MeleeManager && _newAttackID != -1)
|
||||
{
|
||||
@@ -94,7 +93,7 @@ namespace Invector.vCharacterController.AI
|
||||
attackID = MeleeManager.GetAttackID();
|
||||
}
|
||||
|
||||
base.Attack(strongAttack, _newAttackID,forceCanAttack);
|
||||
base.Attack(strongAttack, _newAttackID, forceCanAttack);
|
||||
}
|
||||
|
||||
protected override void UpdateCombatAnimator()
|
||||
@@ -102,9 +101,9 @@ namespace Invector.vCharacterController.AI
|
||||
base.UpdateCombatAnimator();
|
||||
isEquipping = IsAnimatorTag("IsEquipping");
|
||||
if (MeleeManager)
|
||||
{
|
||||
{
|
||||
moveSetID = MeleeManager.GetMoveSetID();
|
||||
defenceID = MeleeManager.GetDefenseID();
|
||||
defenseID = MeleeManager.GetDefenseID();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,23 +118,23 @@ namespace Invector.vCharacterController.AI
|
||||
var damageReduction = MeleeManager.GetDefenseRate();
|
||||
if (damageReduction > 0)
|
||||
damage.ReduceDamage(damageReduction);
|
||||
if (fighter != null && MeleeManager.CanBreakAttack())
|
||||
if (fighter != null && MeleeManager.CanBreakAttack())
|
||||
fighter.OnRecoil(MeleeManager.GetDefenseRecoilID());
|
||||
MeleeManager.OnDefense();
|
||||
}
|
||||
else damage.hitReaction = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void TryApplyRecoil(vIMeleeFighter fighter)
|
||||
{
|
||||
{
|
||||
if (MeleeManager && fighter != null)
|
||||
{
|
||||
if (isBlocking && MeleeManager.CanBlockAttack(fighter.transform.position))
|
||||
{
|
||||
{
|
||||
if (MeleeManager.CanBreakAttack())
|
||||
fighter.OnRecoil(MeleeManager.GetDefenseRecoilID());
|
||||
}
|
||||
fighter.OnRecoil(MeleeManager.GetDefenseRecoilID());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,3 +10,10 @@ MonoImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 123618
|
||||
packageName: Invector FSM AI Template
|
||||
packageVersion: 1.1.9a
|
||||
assetPath: Assets/Invector-FSMAIController/Scripts/AI/AI Controllers/vControlAIMelee.cs
|
||||
uploadId: 601882
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
|
||||
using Invector.IK;
|
||||
using Invector.IK;
|
||||
using Invector.vShooter;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
@@ -30,7 +29,7 @@ namespace Invector.vCharacterController.AI
|
||||
|
||||
protected float _waitingToShot;
|
||||
protected float _upperBodyID;
|
||||
protected float _shotID;
|
||||
protected float _shotID;
|
||||
protected Quaternion handRotationAlignment;
|
||||
protected Quaternion upperArmRotationAlignment;
|
||||
protected float armAlignmentWeight;
|
||||
@@ -84,7 +83,7 @@ namespace Invector.vCharacterController.AI
|
||||
if (CurrentIKAdjustStateWithTag != (IKWeaponTag + TargetIKAdjustState) || _currentIKAdjust == null)
|
||||
{
|
||||
CurrentIKAdjustStateWithTag = (IKWeaponTag + TargetIKAdjustState);
|
||||
CurrentIKAdjustState = TargetIKAdjustState;
|
||||
CurrentIKAdjustState = TargetIKAdjustState;
|
||||
_currentIKAdjust = CurrentWeaponIK.GetIKAdjust(CurrentIKAdjustState, CurrentActiveWeapon.isLeftWeapon);
|
||||
|
||||
}
|
||||
@@ -125,20 +124,20 @@ namespace Invector.vCharacterController.AI
|
||||
{
|
||||
get
|
||||
{
|
||||
return IsAnimatorTag("IgnoreIK");
|
||||
return IsAnimatorTag("IgnoreIK");
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool IsSupportHandIKEnabled
|
||||
{
|
||||
get;protected set;
|
||||
get; protected set;
|
||||
}
|
||||
public void UpdateWeaponIK()
|
||||
{
|
||||
if (shooterManager)
|
||||
{
|
||||
shooterManager.UpdateWeaponIK();
|
||||
if(CurrentWeaponIK) _currentIKAdjust = CurrentWeaponIK.GetIKAdjust(CurrentIKAdjustState, CurrentActiveWeapon.isLeftWeapon);
|
||||
if (CurrentWeaponIK) _currentIKAdjust = CurrentWeaponIK.GetIKAdjust(CurrentIKAdjustState, CurrentActiveWeapon.isLeftWeapon);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -185,43 +184,45 @@ namespace Invector.vCharacterController.AI
|
||||
{
|
||||
get
|
||||
{
|
||||
return isAiming || lockAimDebug;
|
||||
bool enabled = isAiming || lockAimDebug;
|
||||
if (enabled && !isStrafing) isStrafing = true;
|
||||
return enabled;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
private Transform leftUpperArm, rightUpperArm, leftHand, rightHand;
|
||||
private GameObject aimAngleReference;
|
||||
private Quaternion upperArmRotation, handRotation;
|
||||
private readonly float rightRotationWeight;
|
||||
private float _onlyArmsLayerWeight;
|
||||
private float handIKWeight;
|
||||
private float weaponIKWeight;
|
||||
private float aimTime;
|
||||
private float delayEnableAimAfterRagdolled;
|
||||
private int onlyArmsLayer;
|
||||
private int _moveSetID;
|
||||
private int _attackID;
|
||||
private bool aimEnable;
|
||||
protected Transform leftUpperArm, rightUpperArm, leftHand, rightHand;
|
||||
protected GameObject aimAngleReference;
|
||||
protected Quaternion upperArmRotation, handRotation;
|
||||
protected readonly float rightRotationWeight;
|
||||
protected float _onlyArmsLayerWeight;
|
||||
protected float handIKWeight;
|
||||
protected float weaponIKWeight;
|
||||
protected float aimTime;
|
||||
protected float delayEnableAimAfterRagdolled;
|
||||
protected int onlyArmsLayer;
|
||||
protected int _moveSetID;
|
||||
protected int _attackID;
|
||||
protected bool aimEnable;
|
||||
[vEditorToolbar("Debug", overrideChildOrder: true, order = 100)]
|
||||
[SerializeField, vReadOnly(false)] protected bool _canAiming;
|
||||
[SerializeField, vReadOnly(false)] protected bool _canShot;
|
||||
[SerializeField, vReadOnly(false)] protected bool _waitingReload;
|
||||
[SerializeField, vReadOnly(false)] protected int shots;
|
||||
|
||||
|
||||
public bool debugAim;
|
||||
|
||||
public bool lockAimDebug;
|
||||
[SerializeField]
|
||||
[vHideInInspector("lockAimDebug")]
|
||||
private Transform aimDebugTarget = null;
|
||||
protected Transform aimDebugTarget = null;
|
||||
[SerializeField]
|
||||
[vHideInInspector("lockAimDebug")]
|
||||
private bool debugShoots = false;
|
||||
private Vector3 aimVelocity;
|
||||
private Vector3 aimTarget;
|
||||
protected bool debugShoots = false;
|
||||
protected Vector3 aimVelocity;
|
||||
protected Vector3 aimTarget;
|
||||
Vector3 _lastaValidAimLocal;
|
||||
protected bool forceCanShot;
|
||||
protected bool forceCanShot;
|
||||
|
||||
public event IKUpdateEvent onStartUpdateIK;
|
||||
public event IKUpdateEvent onFinishUpdateIK;
|
||||
@@ -288,7 +289,7 @@ namespace Invector.vCharacterController.AI
|
||||
InitShooter();
|
||||
}
|
||||
|
||||
public Vector3 _debugAimPosition;
|
||||
public Vector3 _debugAimPosition;
|
||||
|
||||
public virtual Vector3 defaultValidAimLocal
|
||||
{
|
||||
@@ -342,9 +343,9 @@ namespace Invector.vCharacterController.AI
|
||||
if (debugAim && currentTarget.transform)
|
||||
{
|
||||
Gizmos.DrawSphere(AimPosition, 0.1f);
|
||||
if(currentTarget.collider)
|
||||
if (currentTarget.collider)
|
||||
Gizmos.DrawWireCube(currentTarget.collider.bounds.center, currentTarget.collider.bounds.size);
|
||||
else Gizmos.DrawWireCube(currentTarget.transform.position, Vector3.one*0.5f);
|
||||
else Gizmos.DrawWireCube(currentTarget.transform.position, Vector3.one * 0.5f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -468,11 +469,14 @@ namespace Invector.vCharacterController.AI
|
||||
|
||||
// find states with the IsEquipping tag
|
||||
IsEquipping = IsAnimatorTag("IsEquipping");
|
||||
var _isAiming = isAiming && !IsReloading;
|
||||
var _isAiming = IsAiming && !IsReloading;
|
||||
if (_isAiming && !aimEnable)
|
||||
{
|
||||
shooterManager.CurrentWeapon.onEnableAim.Invoke();
|
||||
aimEnable = true;
|
||||
if (armAlignmentWeight > 0.5f && IsAnimatorTag("Upperbody Pose") && animator.IsInTransition(upperBodyLayer) == false && animatorStateInfos.GetCurrentNormalizedTime(upperBodyLayer) > 0.5f)
|
||||
{
|
||||
shooterManager.CurrentWeapon.onEnableAim.Invoke();
|
||||
aimEnable = true;
|
||||
}
|
||||
}
|
||||
else if (!_isAiming && aimEnable)
|
||||
{
|
||||
@@ -517,7 +521,7 @@ namespace Invector.vCharacterController.AI
|
||||
onStartUpdateIK?.Invoke();
|
||||
if (!IsIgnoreIK)
|
||||
{
|
||||
|
||||
|
||||
if (shooterManager && shooterManager.rWeapon && shooterManager.rWeapon.gameObject.activeSelf)
|
||||
{
|
||||
UpdateIKAdjust(false);
|
||||
@@ -534,7 +538,7 @@ namespace Invector.vCharacterController.AI
|
||||
if (!shooterManager.rWeapon || !shooterManager.rWeapon.gameObject.activeSelf)
|
||||
UpdateSupportHandIK(true);
|
||||
}
|
||||
|
||||
|
||||
if (shots > 0)
|
||||
{
|
||||
Shot();
|
||||
@@ -605,7 +609,6 @@ namespace Invector.vCharacterController.AI
|
||||
ApplyOffsetToTargetBone(isValidIK ? CurrentIKAdjust.supportHintOffset : null, supportHand.middleBoneOffset, !EditingIKGlobalOffset && isValidIK);
|
||||
}
|
||||
|
||||
|
||||
protected virtual void ApplyOffsetToTargetBone(IKOffsetTransform iKOffset, Transform target, bool isValid)
|
||||
{
|
||||
target.localPosition = Vector3.Lerp(target.localPosition, isValid ? iKOffset.position : Vector3.zero, 10f * Time.deltaTime);
|
||||
@@ -634,8 +637,8 @@ namespace Invector.vCharacterController.AI
|
||||
{
|
||||
_localAim = transform.InverseTransformPoint(AimPosition);
|
||||
if (_localAim.z < .5f) _localAim.z = .5f;
|
||||
}
|
||||
return transform.TransformPoint(_localAim);
|
||||
}
|
||||
return transform.TransformPoint(_localAim);
|
||||
}
|
||||
|
||||
protected virtual void UpdateHeadTrack()
|
||||
@@ -660,21 +663,20 @@ namespace Invector.vCharacterController.AI
|
||||
}
|
||||
if (isAiming)
|
||||
{
|
||||
var ikAdjust = isCrouching ? CurrentActiveWeapon.isLeftWeapon ? shooterManager.CurrentWeaponIK.crouchingAimingLeft : shooterManager.CurrentWeaponIK.crouchingAimingRight :
|
||||
CurrentActiveWeapon.isLeftWeapon ? shooterManager.CurrentWeaponIK.standingAimingLeft : shooterManager.CurrentWeaponIK.standingAimingRight;
|
||||
var ikAdjust = CurrentIKAdjust;
|
||||
var offsetSpine = ikAdjust.spineOffset.spine;
|
||||
var offsetHead = ikAdjust.spineOffset.head;
|
||||
_headtrack.offsetSpine = Vector2.Lerp(_headtrack.offsetSpine, offsetSpine, _headtrack.smooth * Time.deltaTime);
|
||||
_headtrack.offsetHead = Vector2.Lerp(_headtrack.offsetHead, offsetHead, _headtrack.smooth * Time.deltaTime);
|
||||
|
||||
_headtrack.offsetSpine = Vector2.Lerp(_headtrack.offsetSpine, offsetSpine, _headtrack.smooth);
|
||||
_headtrack.offsetHead = Vector2.Lerp(_headtrack.offsetHead, offsetHead, _headtrack.smooth);
|
||||
}
|
||||
else
|
||||
{
|
||||
var ikAdjust = isCrouching ? CurrentActiveWeapon.isLeftWeapon ? shooterManager.CurrentWeaponIK.crouchingLeft : shooterManager.CurrentWeaponIK.crouchingRight :
|
||||
CurrentActiveWeapon.isLeftWeapon ? shooterManager.CurrentWeaponIK.standingLeft : shooterManager.CurrentWeaponIK.standingRight;
|
||||
var ikAdjust = CurrentIKAdjust;
|
||||
var offsetSpine = ikAdjust.spineOffset.spine;
|
||||
var offsetHead = ikAdjust.spineOffset.head;
|
||||
_headtrack.offsetSpine = Vector2.Lerp(_headtrack.offsetSpine, offsetSpine, _headtrack.smooth * Time.deltaTime);
|
||||
_headtrack.offsetHead = Vector2.Lerp(_headtrack.offsetHead, offsetHead, _headtrack.smooth * Time.deltaTime);
|
||||
_headtrack.offsetSpine = Vector2.Lerp(_headtrack.offsetSpine, offsetSpine, _headtrack.smooth);
|
||||
_headtrack.offsetHead = Vector2.Lerp(_headtrack.offsetHead, offsetHead, _headtrack.smooth);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -691,24 +693,25 @@ namespace Invector.vCharacterController.AI
|
||||
|
||||
protected virtual void ValidateShotAngle()
|
||||
{
|
||||
if (shooterManager && isAiming && _canAiming)
|
||||
var weapon = CurrentActiveWeapon;
|
||||
if (debugAim && weapon)
|
||||
{
|
||||
var weapon = shooterManager.rWeapon ? shooterManager.rWeapon : shooterManager.lWeapon;
|
||||
Debug.DrawRay(weapon.aimReference.position, weapon.aimReference.forward * 100f, IsInShotAngle ? Color.green : Color.red);
|
||||
}
|
||||
if (shooterManager && isAiming && _canAiming && !IsReloading && !customAction && !isJumping)
|
||||
{
|
||||
|
||||
if (weapon)
|
||||
{
|
||||
var angle = Vector3.Angle(weapon.aimReference.forward, (aimTarget - weapon.aimReference.position).normalized);
|
||||
|
||||
IsInShotAngle = angle <= maxAngleToShot;
|
||||
if (debugAim)
|
||||
{
|
||||
Debug.DrawRay(weapon.aimReference.position, weapon.aimReference.forward * 100f, IsInShotAngle ? Color.green : Color.red);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
IsInShotAngle = false;
|
||||
}
|
||||
|
||||
|
||||
protected virtual void ControlAimTime()
|
||||
{
|
||||
if (aimTime > 0)
|
||||
@@ -716,7 +719,10 @@ namespace Invector.vCharacterController.AI
|
||||
|
||||
aimTime -= Time.deltaTime;
|
||||
}
|
||||
else if (isAiming) isAiming = false;
|
||||
else if (isAiming)
|
||||
{
|
||||
isAiming = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void UpdateSupportHandIK(bool isUsingLeftHand = false)
|
||||
@@ -752,7 +758,7 @@ namespace Invector.vCharacterController.AI
|
||||
if (IsAnimatorTag("Shot") && weapon.disableIkOnShot) { handIKWeight = 0; return; }
|
||||
|
||||
bool useIkConditions = false;
|
||||
var animatorInput = System.Math.Round(animator.GetFloat("InputMagnitude"),1);
|
||||
var animatorInput = System.Math.Round(animator.GetFloat("InputMagnitude"), 1);
|
||||
if (!IsAiming && !isAttacking)
|
||||
{
|
||||
var locomotionValidation = isStrafing ? CurrentActiveWeapon.strafeIKOptions : CurrentActiveWeapon.freeIKOptions;
|
||||
@@ -786,15 +792,15 @@ namespace Invector.vCharacterController.AI
|
||||
useIkConditions = CurrentActiveWeapon.useIkAttacking;
|
||||
}
|
||||
|
||||
IsSupportHandIKEnabled = useIkConditions;
|
||||
IsSupportHandIKEnabled = useIkConditions;
|
||||
if (isUsingLeftHand)
|
||||
{
|
||||
targetIK = RightIK;
|
||||
targetIK = RightIK;
|
||||
}
|
||||
else
|
||||
{
|
||||
targetIK = LeftIK;
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (targetIK != null)
|
||||
@@ -824,17 +830,17 @@ namespace Invector.vCharacterController.AI
|
||||
if (handIKWeight <= 0) return;
|
||||
// update IK
|
||||
targetIK.SetIKWeight(handIKWeight);
|
||||
|
||||
|
||||
if (shooterManager && weapon && weapon.handIKTarget)
|
||||
{
|
||||
|
||||
|
||||
targetIK.SetIKPosition(weapon.handIKTargetOffset.position);
|
||||
targetIK.SetIKRotation(weapon.handIKTargetOffset.rotation);
|
||||
if (shooterManager.CurrentWeaponIK)
|
||||
{
|
||||
targetIK.AnimationToIK();
|
||||
targetIK.AnimationToIK();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -848,7 +854,7 @@ namespace Invector.vCharacterController.AI
|
||||
{
|
||||
if (!shooterManager) return;
|
||||
|
||||
armAlignmentWeight = (isAiming) && !IsReloading && CanRotateAimArm()&&_canAiming ? Mathf.Lerp(armAlignmentWeight, 1f, smoothArmAlignmentWeight * (Time.deltaTime)) : 0f;
|
||||
armAlignmentWeight = (isAiming) && !IsReloading && CanRotateAimArm() && _canAiming ? Mathf.Lerp(armAlignmentWeight, 1f, smoothArmAlignmentWeight * (Time.deltaTime)) : 0f;
|
||||
if (CurrentActiveWeapon && armAlignmentWeight > 0.1f && CurrentActiveWeapon.alignRightUpperArmToAim)
|
||||
{
|
||||
var aimPoint = AimPositionClamped();
|
||||
@@ -876,7 +882,7 @@ namespace Invector.vCharacterController.AI
|
||||
float _armAlignmentWeight = CurrentActiveWeapon.alignRightHandToAim ? armAlignmentWeight * 0.5f : armAlignmentWeight;
|
||||
upperArm.localRotation *= Quaternion.Euler(upperArmRotation.eulerAngles.NormalizeAngle() * _armAlignmentWeight);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -888,7 +894,7 @@ namespace Invector.vCharacterController.AI
|
||||
{
|
||||
if (!shooterManager) return;
|
||||
|
||||
if (CurrentActiveWeapon && armAlignmentWeight > 0.1f && CurrentActiveWeapon.alignRightHandToAim)
|
||||
if (CurrentActiveWeapon && armAlignmentWeight > 0.1f && CurrentActiveWeapon.alignRightHandToAim)
|
||||
{
|
||||
var aimPoint = AimPositionClamped();
|
||||
Vector3 v = aimPoint - CurrentActiveWeapon.aimReference.position;
|
||||
@@ -923,10 +929,8 @@ namespace Invector.vCharacterController.AI
|
||||
p1.y = transform.position.y;
|
||||
var angle = Vector3.Angle(transform.forward, p1 - transform.position);
|
||||
|
||||
var outAngle = (angle > aimTurnAngle);
|
||||
//var aimLocalPoint = transform.InverseTransformPoint(aimTarget);
|
||||
//var can = aimLocalPoint.z > _capsuleCollider.radius && Mathf.Abs(aimLocalPoint.x) > _capsuleCollider.radius;
|
||||
_canAiming = !outAngle;
|
||||
var outAngle = (angle > aimTurnAngle);
|
||||
_canAiming = true;
|
||||
if (outAngle && isAiming) RotateTo(aimTarget - transform.position);
|
||||
}
|
||||
|
||||
@@ -943,7 +947,7 @@ namespace Invector.vCharacterController.AI
|
||||
{
|
||||
shooterManager.Shoot(CurrentActiveWeapon.muzzle.position + CurrentActiveWeapon.muzzle.forward * 100);
|
||||
shots--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else if (!IsReloading && !_waitingReload)
|
||||
@@ -952,7 +956,7 @@ namespace Invector.vCharacterController.AI
|
||||
|
||||
if (!_canShot && !IsReloading && !_waitingReload && doReloadWhileWaiting && shooterManager.CurrentWeapon.ammoCount < shooterManager.CurrentWeapon.clipSize)
|
||||
{
|
||||
shooterManager.ReloadWeapon();
|
||||
StartCoroutine(Reload());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,3 +10,10 @@ MonoImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 123618
|
||||
packageName: Invector FSM AI Template
|
||||
packageVersion: 1.1.9a
|
||||
assetPath: Assets/Invector-FSMAIController/Scripts/AI/AI Controllers/vControlAIShooter.cs
|
||||
uploadId: 601882
|
||||
|
||||
Reference in New Issue
Block a user