void DoBehaviour(RaycastHit hit) { if (!m_leavingGround) { // If the player is facing away from its movement vector, change to switch. Otherwise, they are in the regular stance float fwdVelDot = Vector3.Dot(transform.forward, m_rb.velocity); if (m_switch && fwdVelDot > 0) { m_switch = false; TrickManager.GetInstance().WriteToStanceTextBox("Regular"); } else if (!m_switch && fwdVelDot < 0) { m_switch = true; TrickManager.GetInstance().WriteToStanceTextBox("Switch"); } // Find the vector in front of the player or under the player that best suits m_moveDir = (m_switch) ? -transform.forward : transform.forward; // Find the degree to which the curent terrain and the previous differ Vector3 lastUp = m_currentUp; float transitionAngle = Vector3.Angle(lastUp, hit.normal); // If that angle is too high, stop sticking to the ground and instead, leave the ground. if (transitionAngle >= m_maxAdhesionDelta) { LeaveGround(); } SetGroundedData(hit); } }
/// <summary> /// Update the player's controller /// </summary> public void UpdatePlayer() { SetPlayerUp(); UpdateRotation(); UpdateCamera(); //DebugDropIn(); TrickManager.GetInstance().WriteToSpeedTextBox(m_rb.velocity.magnitude + ""); }
/// <summary> /// Make the player jump /// </summary> public void Jump() { if (m_touchingGround) { m_rb.velocity += Vector3.up * m_jumpAmount; } m_grinding = false; LeaveGround(); TrickManager.GetInstance().WriteToTrickTextBox("Ollie"); }
protected void DoAtStart() { gm = GameManager_Trapeze.GetInstance(); InitRBs(); if (!facingRight) { facingRight = true; TurnAround(); } AttachTo(attachedTo); lowerLegsRB.AddForce(10 * Vector2.right, ForceMode2D.Impulse); tm = TrickManager.GetInstance(); animator.enabled = false; //TurnAround(); }
// Start is called before the first frame update void Start() { switch (m_boxType) { case (BoxType.Tricks): TrickManager.GetInstance().SetTrickBox(m_textBox); break; case (BoxType.Stance): TrickManager.GetInstance().SetStanceBox(m_textBox); break; case (BoxType.Speed): TrickManager.GetInstance().SetSpeedBox(m_textBox); break; } }
public void DetectDuoTrick(string number, string trickName, string nextNode, string wrongNode) { if (detecting) { return; } detecting = true; SetTarget("player"); if (targetManager == null) { return; } numDetected = 0; targetNum = int.Parse(number); successNode = nextNode; failNode = wrongNode; targetTrick = trickName; TrickManager.GetInstance().OnDuoTrick += this.InvokeDuoTrickDetected; }
/// <summary> /// Drop into a bank or other sufficiently sloped surface /// </summary> public bool DropIn() { if (!m_droppingIn && !m_touchingGround && m_rb.velocity.y > 0.5f) { bool rampFound = false; float spacing = 0.5f; int numOfRaysToCast = 30; // Pick the best direction to look for a slope Vector3 bestVector; float angleDelta = Vector3.Angle(m_currentUp, Vector3.up); if (angleDelta <= 45) { bestVector = m_moveDir; } else { bestVector = -transform.up; } // Make the vector only use X and Z, then normalize bestVector.y = 0; bestVector.Normalize(); // Perform a series of raycasts in front of the player for (int i = 1; i <= numOfRaysToCast; i++) { if (!rampFound) { if (Physics.Raycast(transform.position + (bestVector * spacing * i), Vector3.down, out RaycastHit hit)) { rampFound = TryDropinLocation(hit); if (rampFound) { TrickManager.GetInstance().WriteToTrickTextBox("Transfer"); return(true); } } } } } return(false); }
private void DuoTrickDetected() { if (!detecting) { return; } if (targetManager.GetLastTrickPerformed().Equals(targetTrick)) { numDetected++; if (numDetected >= targetNum) { TrickManager.GetInstance().OnDuoTrick -= this.InvokeDuoTrickDetected; string s = successNode; ResetVars(); dialogueRunner.StartDialogue(s); } } else { dialogueRunner.StartDialogue(failNode); } }
public void Grind() { float sphereRad = 2f; // Perform a spherecast. If anything the cast touches has a rail, add it to a list of possible rails. Collider[] hitColliders = Physics.OverlapSphere(transform.position, sphereRad); if (hitColliders.Length > 0) { // Look through the list of rails and find the spline that is closest to the player. List <RailData> rails = new List <RailData>(); foreach (var c in hitColliders) { Transform parent = c.transform; while (parent != null) { RailData railData = parent.GetComponent <RailData>(); if (railData) { bool sameRail = false; foreach (var rail in rails) { if (rail == railData) { sameRail = true; break; } } if (!sameRail) { rails.Add(railData); } break; } else { parent = parent.parent; } } } if (rails.Count > 0) { // Default to the first rail BGCcMath closestRail = rails[0].m_railData[0]; float closestDist = Vector3.Distance(transform.position, rails[0].m_railData[0].CalcPositionByClosestPoint(transform.position)); foreach (var rail in rails) { foreach (var r in rail.m_railData) { // Find the coping that is nearest to the player float newClosestDist = Vector3.Distance(transform.position, r.CalcPositionByClosestPoint(transform.position)); if (newClosestDist < closestDist) { closestRail = r; closestDist = newClosestDist; } } } if (closestDist <= sphereRad) { // If the player is facing away from its movement vector, change to switch. Otherwise, they are in the regular stance float fwdVelDot = Vector3.Dot(transform.forward, m_rb.velocity); if (m_switch && fwdVelDot > 0) { m_switch = false; TrickManager.GetInstance().WriteToStanceTextBox("Regular"); } else if (!m_switch && fwdVelDot < 0) { m_switch = true; TrickManager.GetInstance().WriteToStanceTextBox("Switch"); } // Find the vector in front of the player or under the player that best suits m_moveDir = (m_switch) ? -transform.forward : transform.forward; m_currentRail = closestRail; m_grinding = true; } } } }