//Comprueba si el coche está yendo marcha atrás, y establece el punto al que se ha de colocar al jugador en caso de que vuelque. public void UpdateRaceCarState(PlayerInfo player, SetupPlayer setupPlayer) { Vector3 carPos = player.transform.position; Vector3 carFwd = player.transform.forward; int segIdx; float carDist; Vector3 carProj; float minArcL = this.m_CircuitController.ComputeClosestPointArcLength(carPos, out segIdx, out carProj, out carDist); //Se actualizan los datos de recuperación de choques del jugador setupPlayer.CmdChangeLastSafePosition(carProj); setupPlayer.CmdChangeCrashRecoverForward(m_CircuitController.GetSegment(segIdx)); //Comprobación de si va hacia atrás (según el ángulo entre el forward del coche y la dirección del circuito) float ang = Vector3.Angle(m_CircuitController.GetSegment(segIdx), carFwd); bool goingBackwards = ang > goingBackwardsThreshold; if (goingBackwards != player.goingBackwards) { setupPlayer.CmdChangeGoingBackwards(goingBackwards); } }
/*Se encarga de calcular la distancia recorrida desde el inicio de la carrera, teniendo en cuenta el número de vueltas.*/ float ComputeCarArcLength(int ID) { // Compute the projection of the car position to the closest circuit // path segment and accumulate the arc-length along of the car along // the circuit. Vector3 carPos = this.m_Players[ID].transform.position; int segIdx; float carDist; Vector3 carProj; float minArcL = this.m_CircuitController.ComputeClosestPointArcLength(carPos, out segIdx, out carProj, out carDist); m_Players[ID].currentSegDir = m_CircuitController.GetSegment(segIdx); if (m_Players[ID].CircuitProgress.UpdateProgress(minArcL / m_CircuitController.CircuitLength)) { m_Players[ID].AddLap(); } //this.m_DebuggingSpheres[ID].transform.position = carProj; minArcL += m_CircuitController.CircuitLength * (m_Players[ID].CurrentLap); return(minArcL); }
/* * Este modo de cámara proporciona una vista aérea al jugador */ void CinematicMode() { if (this.m_Circuit != null) { if (this.m_Direction.magnitude == 0) { this.m_Direction = new Vector3(0f, -1f, 0f); } int segIdx; float carDist; Vector3 carProj; m_Circuit.ComputeClosestPointArcLength(m_Focus.transform.position, out segIdx, out carProj, out carDist); Vector3 pathDir = -m_Circuit.GetSegment(segIdx); pathDir = new Vector3(pathDir.x, 0f, pathDir.z); pathDir.Normalize(); this.m_Direction = Vector3.Lerp(this.m_Direction, pathDir, this.m_Following * Time.deltaTime); Vector3 offset = this.m_Direction * this.m_Distance; offset = new Vector3(offset.x, m_Elevation, offset.z); mainCamera.transform.position = m_Focus.transform.position + offset; mainCamera.transform.LookAt(m_Focus.transform.position); } else { mainCamera.transform.position = m_Focus.transform.position + m_offset; mainCamera.transform.LookAt(m_Focus.transform.position); } }
void SavePlayer() { int segId; Vector3 posProj; float dist; float arcLen = circuitController.ComputeClosestPointArcLength(transform.position, out segId, out posProj, out dist); RaycastHit hit; Vector3 up = Vector3.up; if (Physics.Raycast(posProj + Vector3.up * 0.1f, -Vector3.up, out hit, Mathf.Infinity)) { posProj = hit.point + Vector3.up * 0.05f; up = hit.normal; } transform.position = posProj; Vector3 dir = circuitController.GetSegment(segId); dir = Vector3.ProjectOnPlane(dir, up).normalized; transform.forward = dir; m_Rigidbody.velocity = Vector3.zero; m_Rigidbody.angularVelocity = Vector3.zero; m_PlayerInfo.SetSpeed(0); m_PlayerInfo.RpcResetCam(); }