protected override void Action(AIBehaviors fsm) { Transform target = fsm.GetClosestPlayer(); if ( target != null ) { fsm.RotateAgent(target, rotationSpeed); } AIBehaviorsAnimationState animState = fsm.animationStates.GetStateWithName(attackAnimName); fsm.PlayAnimation(animState); if ( scriptWithAttackMethod != null ) { if ( !string.IsNullOrEmpty(methodName) ) { if ( attackAnimation != null && attackAnimation[attackAnimName] != null ) { float curAnimPosition = attackAnimation[attackAnimName].normalizedTime % 1.0f; if ( previousSamplePosition > attackPoint || curAnimPosition < attackPoint ) { previousSamplePosition = curAnimPosition; return; } previousSamplePosition = curAnimPosition; } scriptWithAttackMethod.SendMessage(methodName, new AIBehaviors_AttackData(attackDamage)); fsm.PlayAudio(); } } }
protected Transform GetTarget(AIBehaviors fsm) { if (findVisibleTargetsOnly) { return(fsm.GetClosestPlayerWithinSight(objectFinder.GetTransforms(SearchType.Enemy))); } else { return(fsm.GetClosestPlayer(objectFinder.GetTransforms(SearchType.Enemy))); } }
protected override bool Evaluate(AIBehaviors fsm) { if (navMeshAgent != null) { Transform targetTransform = fsm.GetClosestPlayer(objectFinder.GetTransforms()); if (targetTransform != null) { Vector3 targetPosition = targetTransform.position; Vector3 currentDestination = targetPosition; if (path == null) { path = new NavMeshPath(); } if (currentDestination != previousDestination) { previousDestination = currentDestination; navMeshAgent.CalculatePath(currentDestination, path); } if (path.status != NavMeshPathStatus.PathInvalid) { Vector3[] points = path.corners; if (points.Length > 0) { Vector3 lastPoint = points[points.Length - 1]; float sqrThreshold = ureachableThreshold * ureachableThreshold; float sqrDist; bool result; if (ignoreYPosition) { lastPoint.y = 0.0f; targetPosition.y = 0.0f; } sqrDist = Vector3.SqrMagnitude(lastPoint - targetPosition); result = sqrDist < sqrThreshold; return(result); } } } } // This will force the trigger status to be false even if they use the invertResult option return(!invertResult); }