public override NodeState RunNode(float p_delta) { Script_IEntity targetEntity = _tree.GetBlackBoardElement <Script_IEntity>(_targetEnemyFlag); bool isForwardSwing = _tree.GetBlackBoardElement <bool> (_isForwardSwingFlag); if (targetEntity == null || targetEntity.GetGameObject() == null) { return(NodeState.Failed); } if (isForwardSwing) { NodeState success = ForwardSwing(p_delta, _entityToAttack.GetGridLocation(), _entityToAttack, targetEntity); if (success == NodeState.Success) { targetEntity.TakeDamage(_entityToAttack, _entityToAttack.GetStats()._damage); return(NodeState.Success); } } else if (!isForwardSwing) { BackSwing(p_delta, _entityToAttack.GetGridLocation(), _entityToAttack, targetEntity); } return(NodeState.Running); }
private void MoveTowardsEntity(Script_IEntity p_attackerEntity, Script_IEntity p_toEntity, float p_delta) { Vector3 movementDirection = (p_toEntity.GetPosition() - _projectileObject.transform.position).normalized; Vector3 nextStep = _projectileObject.transform.position + (movementDirection * _speed * Time.deltaTime); if (Vector3.Distance(nextStep, p_toEntity.GetPosition()) >= Vector3.Distance(_projectileObject.transform.position, p_toEntity.GetPosition())) { _projectileObject.transform.position = p_toEntity.GetPosition(); p_toEntity.TakeDamage(p_attackerEntity, _startEntity.GetStats()._damage); Destruction(); } if (Vector3.Distance(nextStep, p_toEntity.GetPosition()) < Vector3.Distance(_projectileObject.transform.position, p_toEntity.GetPosition())) { _projectileObject.transform.position = nextStep; } }