bool TryToChangeHeight(int index) { var currentAgentPosition = _shipMovement.CurrentAgentPosition(); var targetPosition = currentAgentPosition; targetPosition.y = gameSpace.heights[index]; var direction = (targetPosition - currentAgentPosition).normalized; var ray = new Ray(currentAgentPosition, Vector3.up * direction.y); RaycastHit hit; bool changeable = true; if (Physics.Raycast(ray, out hit, Mathf.Infinity)) { changeable = hit.collider.tag != "Obstacle"; } if (!changeable) { return(false); } _shipMovement.ChangeCurrentAgentPosition(targetPosition); return(true); }