/// <summary> /// Check if the predator is facing an obstacle /// </summary> /// <param name="obstacleHeight">output the height of the obstacle</param> /// <param name="obstacleWidth">output the width of the obstacle</param> /// <param name="DistanceToObstacle">output the distance from predator to the obstacle</param> /// <returns></returns> bool CheckJumpOverObstacle(out JumpOverObstacle Obstacle) { RaycastHit hitInfo; if (Physics.Raycast(transform.position, transform.forward * JumpoverCheckDistance, out hitInfo, JumpoverCheckDistance, JumpOverObstacleLayer)) { JumpOverObstacle obstacle = hitInfo.collider.GetComponent <JumpOverObstacle>(); Obstacle = obstacle; return(true); } else { Obstacle = null; return(false); } }
/// <summary> /// Trigger a Jump beheavior. /// if there is a jump over obstacle ahead, jump over it. /// else , jump forward. /// </summary> /// <param name='Power'> /// Power - a value to indicate the jump power, if power = 1, means the predator will jump max forward distance. /// Note: the power is eventually converted to time : /// - if power = 1, the jumpforward time = ForwardJumpTime. /// - if power = 0 (which is not possible, beacuse min-power = 0.2f, but in theory), means the jumpforward time = 0. /// Note: power is only applicable for jump forward case. /// </param> public IEnumerator Jump(float Power) { if (IsJumping) { yield break; } // Debug.Log("Jump at frame:" + Time.frameCount + " isJumping:" + IsJumping + " at time:" + Time.time + "at jump power:" + Power); JumpOverObstacle obstacle = null; bool HasObstacle = CheckJumpOverObstacle(out obstacle); Debug.Log("Check obstacle:" + HasObstacle); //If there is obstacle, jump over it if (HasObstacle) { Vector3 HeightPoint, GroundPoint; obstacle.GetJumpOverTrack(transform, out HeightPoint, out GroundPoint); yield return(StartCoroutine(JumpOverSmoothly(HeightPoint, GroundPoint))); } //Else, jump forward else { yield return(StartCoroutine(JumpStraightForward(Power))); } }
/// <summary> /// Check if the predator is facing an obstacle /// </summary> /// <param name="obstacleHeight">output the height of the obstacle</param> /// <param name="obstacleWidth">output the width of the obstacle</param> /// <param name="DistanceToObstacle">output the distance from predator to the obstacle</param> /// <returns></returns> bool CheckJumpOverObstacle(out JumpOverObstacle Obstacle) { RaycastHit hitInfo; if (Physics.Raycast(transform.position, transform.forward * JumpoverCheckDistance, out hitInfo, JumpoverCheckDistance, JumpOverObstacleLayer)) { JumpOverObstacle obstacle = hitInfo.collider.GetComponent<JumpOverObstacle>(); Obstacle = obstacle; return true; } else { Obstacle = null; return false; } }