private void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag("Halfpipe")) { m_CurrentHalfPipe = other.GetComponent <HalfPipe>(); } }
//Air movement while above a half pipe (but not doing an aerial) private void MoveAirHalfpipe() { //apply the current airial velocity Vector3 pos = transform.position; pos += m_AirVelocity * Time.deltaTime; m_CurrentHalfPipe.SetAngleToAirbornePos(pos); //Apply to the grounded position m_GroundedPosition += m_CurrentHalfPipe.ProjectAlongForward(m_AirVelocity) * Time.deltaTime; //rotate transform.rotation = m_CurrentHalfPipe.GetRotation() * Quaternion.Euler(0, m_CurrentAngle, 0); //apply gravity to the velocity for next frame m_AirVelocity += Vector3.down * m_Gravity * Time.deltaTime; //check for landing on halfpipe float landingPos = m_CurrentHalfPipe.GetLandingHeight(pos); if (pos.y < landingPos) { pos.y = landingPos; m_CurrentState = PlayerState.Base; } if (m_CurrentHalfPipe.CrossedGroundThreshhold) { m_CurrentHalfPipe = null; } transform.position = pos; }
//doing an aerial (sideways jump) private void HalfpipeAerial(HalfPipe pipe) { //rotate player towards gravity m_CurrentAngle += m_AerialRotationalGravity * Time.deltaTime * pipe.GetAerialRotationDirection(); //generate velocity(nothing else can modify this) Vector3 velocity = transform.forward * m_Speed; //apply full movement (not ramp local) //manually applied to ignore grounded pos transform.position += velocity * Time.deltaTime; velocity.y = 0f; m_GroundedPosition += velocity * Time.deltaTime; transform.rotation = pipe.GetRotation() * Quaternion.Euler(0, m_CurrentAngle, 0); //check if player is now back on the ramp if (transform.position.y <= /*pipe.m_Pivot.position.y*/ 3) { m_CurrentState = PlayerState.Base; } }
private void HalfpipeGrounded(HalfPipe pipe) { Vector3 velocity = Quaternion.Euler(0, m_CurrentAngle, 0) * Vector3.forward * m_Speed; velocity = pipe.ApplyVector(velocity); //apply the remaining velocity ApplyVelocity(velocity); transform.rotation = pipe.GetRotation() * Quaternion.Euler(0, m_CurrentAngle, 0); transform.position = m_GroundedPosition + pipe.GetAnglePosition(); if (pipe.CrossedJumpThreshhold) { pipe.SetAngle(90.0f); m_CurrentState = PlayerState.PipeAerial; } else if (pipe.CrossedGroundThreshhold) { pipe.SetAngle(0.0f); m_CurrentHalfPipe = null; transform.rotation = Quaternion.Euler(0, m_CurrentAngle, 0); transform.position = m_GroundedPosition; } }