/// <summary> /// Update both the trajectory and landing position if both possible and desired. /// </summary> private void Update() { // The script should work fine even if there's no trajectory attached. if (m_trajectory != null) { // Only draw if requested by the controlling script. if (m_bDisplayTrajectory) { m_trajectory.SetInitialPositionAndVelocity(m_vInitialPosition, m_vKickVelocity); m_trajectory.OnSetShouldDraw(true); } else { m_trajectory.OnSetShouldDraw(false); } } // The script should work fine even if there's no landing position object attached. if (m_landingPosition != null) { // Only draw if requested by the controlling script. if (m_bDisplayLandingPosition) { m_landingPosition.SetActive(true); m_landingPosition.transform.position = ProjectileBehaviour.GetLandingPosition(m_vInitialPosition, m_vKickVelocity); } else { m_landingPosition.SetActive(false); } } }
/// <summary> /// Kicks the ball using the velocity set by OnSetKickVelocity(). /// </summary> public void OnKick() { if (!m_bIsGrounded) // Ball cannot be kicked if it's already in the air. { return; } // Determine the target position and face in that direction. Vector3 targetPosition = ProjectileBehaviour.GetLandingPosition(transform.position, m_vKickVelocity); transform.LookAt(targetPosition, Vector3.up); // Note that the ball is in the air, then actually make it so. m_bIsGrounded = false; m_rb.velocity = m_vKickVelocity; }