public override NodeState RunNode(float p_delta) { _location = _tree.GetBlackBoardElement <Vector3Int>(_locationFlag); GameObject entObject = _entity.GetGameObject(); Vector3 entityPosition = entObject.transform.position; Vector3 entityDirection = (_location - entObject.transform.position).normalized; Vector3 nextStep = entObject.transform.position + (entityDirection * Time.deltaTime); if (Vector3.Distance(nextStep, _location) >= Vector3.Distance(entityPosition, _location)) { entObject.transform.position = _location; return(NodeState.Success); } if (Vector3.Distance(nextStep, _location) < Vector3.Distance(entityPosition, _location)) { _entity.GetGameObject().transform.position += entityDirection * Time.deltaTime; return(NodeState.Running); } return(NodeState.Failed); }
private NodeState ForwardSwing(float p_delta, Vector3Int p_anchorPoint, Script_IEntity p_attackerEntity, Script_IEntity p_targetEntity) { GameObject attackerObject = p_attackerEntity.GetGameObject(); GameObject targetObject = p_targetEntity.GetGameObject(); Vector3 forwardSwingPoint = (targetObject.transform.position - attackerObject.transform.position).normalized; Vector3 nextPosition = attackerObject.transform.position + (forwardSwingPoint * p_delta); float forwardSwingSpeed = p_attackerEntity.GetStats()._attackSpeed * 3; if (Vector3.Distance(p_anchorPoint, nextPosition) > _swingDistance) { attackerObject.transform.position = p_anchorPoint + (forwardSwingPoint * _swingDistance); Script_Projectile projectile = new Script_Projectile(_manager, p_attackerEntity, p_targetEntity, _projectileColor); _manager.CreateProjectile(projectile as Script_IProjectile); _tree.SetBlackboardElement(_isForwardSwingFlag, false); return(NodeState.Success); } else { attackerObject.transform.position += forwardSwingPoint * p_delta * forwardSwingSpeed; } return(NodeState.Running); }
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) { Script_Projectile projectile = new Script_Projectile(_manager, _entityToAttack, targetEntity, _projectileColor); _manager.CreateProjectile(projectile); return(NodeState.Success); } } else if (!isForwardSwing) { BackSwing(p_delta, _entityToAttack.GetGridLocation(), _entityToAttack, targetEntity); } return(NodeState.Running); }
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 NodeState ForwardSwing(float p_delta, Vector3Int p_anchorPoint, Script_IEntity p_attackerEntity, Script_IEntity p_targetEntity) { GameObject attackerObject = p_attackerEntity.GetGameObject(); GameObject targetObject = p_targetEntity.GetGameObject(); Vector3 forwardSwingPoint = (targetObject.transform.position - attackerObject.transform.position).normalized; Vector3 nextPosition = attackerObject.transform.position + (forwardSwingPoint * p_delta); float forwardSwingSpeed = p_attackerEntity.GetStats()._attackSpeed * 3; float upSwingSpeed = forwardSwingSpeed * 0.5f; if (attackerObject == targetObject) { NodeState state = JumpForwardAnimation(p_attackerEntity, upSwingSpeed); if (state == NodeState.Success) { return(state); } } else { if (Vector3.Distance(p_anchorPoint, nextPosition) > _swingDistance) { attackerObject.transform.position = p_anchorPoint + (forwardSwingPoint * _swingDistance); _tree.SetBlackboardElement(_isForwardSwingFlag, false); return(NodeState.Success); } else { attackerObject.transform.position += forwardSwingPoint * p_delta * forwardSwingSpeed; } } return(NodeState.Running); }
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) { Script_HealingVisualEffect healingEffect = new Script_HealingVisualEffect(_manager, targetEntity); _manager.CreateVisual(healingEffect); targetEntity.Heal(_entityToAttack.GetStats()._healPower); return(NodeState.Success); } } else if (!isForwardSwing) { BackSwing(p_delta, _entityToAttack.GetGridLocation(), _entityToAttack, targetEntity); } return(NodeState.Running); }
private NodeState BackSwing(float p_delta, Vector3Int p_anchorPoint, Script_IEntity p_attackerEntity, Script_IEntity p_targetEntity) { GameObject attackerObject = p_attackerEntity.GetGameObject(); GameObject targetObject = p_targetEntity.GetGameObject(); Vector3 backSwingPoint = (attackerObject.transform.position - targetObject.transform.position).normalized; Vector3 nextPosition = attackerObject.transform.position + (backSwingPoint * p_delta); float backSwingSpeed = p_attackerEntity.GetStats()._attackSpeed; float downSwingSpeed = backSwingSpeed * 0.5f; if (attackerObject == targetObject) { JumpDownAnimation(p_attackerEntity, downSwingSpeed); } else { if (Vector3.Distance(p_anchorPoint, nextPosition) > _swingDistance) { attackerObject.transform.position = p_anchorPoint + (backSwingPoint * _swingDistance); _tree.SetBlackboardElement(_isForwardSwingFlag, true); } else { attackerObject.transform.position += backSwingPoint * p_delta * backSwingSpeed; } } return(NodeState.Running); }
public override NodeState RunNode(float p_delta) { if (_entityToMove == null) { return(NodeState.Failed); } _targetEntity = _tree.GetBlackBoardElement <Script_IEntity>(_entityFlag); if (_targetEntity == null || _targetEntity.GetGameObject() == null) { return(NodeState.Failed); } int maxRange = _grid.GetWidth() > _grid.GetHeight() ? _grid.GetWidth() : _grid.GetHeight(); int currentRange = 1; List <Script_Tile> availableTiles = new List <Script_Tile> (); while (currentRange <= maxRange && availableTiles.Count == 0) { availableTiles = GetAvailableTilesSurroundingEntity(currentRange, _targetEntity); } if (availableTiles.Count == 0) { return(NodeState.Failed); } foreach (Script_Tile tile in availableTiles) { if (_entityToMove.GetGridLocation() == tile.GetGridPosition() || _entityToMove.GetGridLocation() == _targetEntity.GetGridLocation()) { return(NodeState.Success); } } GameObject entityObject = _entityToMove.GetGameObject(); GameObject targetEntityObject = _targetEntity.GetGameObject(); entityObject.transform.position += (targetEntityObject.transform.position - entityObject.transform.position).normalized * p_delta; return(NodeState.Running); }
public override NodeState RunNode(float p_delta) { GameObject entObject = _entity.GetGameObject(); Vector3 entityPosition = entObject.transform.position; if (_tree.GetBlackBoardElement <Vector3> (_locationFlag) == entityPosition) { return(NodeState.Success); } return(NodeState.Failed); }
private void JumpDownAnimation(Script_IEntity p_jumpingEntity, float p_speed) { GameObject jumpingObject = p_jumpingEntity.GetGameObject(); float groundHeight = _manager.GetGrid().GetGridDepthPosition(); if ((jumpingObject.transform.position.y - groundHeight) < groundHeight) { _tree.SetBlackboardElement(_isForwardSwingFlag, true); } else { jumpingObject.transform.position += new Vector3(0, -1, 0) * p_speed * Time.deltaTime; } }
private NodeState JumpForwardAnimation(Script_IEntity p_jumpingEntity, float p_speed) { GameObject jumpingObject = p_jumpingEntity.GetGameObject(); float groundHeight = _manager.GetGrid().GetGridDepthPosition(); if ((jumpingObject.transform.position.y - groundHeight) > _swingDistance) { _tree.SetBlackboardElement(_isForwardSwingFlag, false); return(NodeState.Success); } else { jumpingObject.transform.position += new Vector3(0, 1.0f, 0) * p_speed * Time.deltaTime; } return(NodeState.Running); }