//------------------------------------------------------------------------- // get current received map position of vehicle and set the vehiclemarkes accordingly public void setVehiclePositions() { foreach (WbCompMapVehicle vehicle in vehicleMapMarkers) { // Positions foreach (KeyValuePair <VehicleID, Vector3> vehiclePositions in WbCompStateSyncReceiving.getInstance().getVehicleMapPositionList()) { if (vehiclePositions.Key.Equals(vehicle.vehicleId)) { Vector3 pos = vehicle.transform.position; vehicle.transform.position = Vector3.Lerp(pos, vehiclePositions.Value, Time.deltaTime * dampingFactor); } } // Rotations foreach (KeyValuePair <VehicleID, Quaternion> vehicleRotations in WbCompStateSyncReceiving.getInstance().getVehicleMapRotationList()) { if (vehicleRotations.Key.Equals(vehicle.vehicleId)) { Quaternion rot = vehicle.transform.rotation; vehicle.transform.rotation = Quaternion.Lerp(rot, vehicleRotations.Value, Time.deltaTime * dampingFactor); } } } }
//--------------------------------------------------------------------- public void setInstrumentsOnUpdate() { float rpm = WbCompStateSyncReceiving.getInstance().vehicleRPM; float speed = WbCompStateSyncReceiving.getInstance().vehicleSpeed; //rpm = 1800f; //speed = 80f; if (instrumentType == vehicleInstrumentType.RPM) { Quaternion prevRotation = gameObject.transform.localRotation; float rpmAngle = Mathf.Lerp(0, maxRotation, Mathf.InverseLerp(0, 3500, rpm)); Quaternion targetRotation = Quaternion.Euler(0f, 0f, rpmAngle); gameObject.transform.localRotation = Quaternion.Lerp(prevRotation, targetRotation, Time.deltaTime * this.dampingFactor); } if (instrumentType == vehicleInstrumentType.Speed) { Quaternion prevRotation = gameObject.transform.localRotation; float speedAngle = Mathf.Lerp(0, maxRotation, Mathf.InverseLerp(0, 100, speed)); Quaternion targetRotation = Quaternion.Euler(0f, 0f, speedAngle); gameObject.transform.localRotation = Quaternion.Lerp(prevRotation, targetRotation, Time.deltaTime * this.dampingFactor); } if (instrumentType == vehicleInstrumentType.Fuel) { float zValue = 55f; Quaternion prevRotation = gameObject.transform.localRotation; Quaternion targetRotation = Quaternion.Euler(0f, 0f, zValue); gameObject.transform.localRotation = Quaternion.Lerp(prevRotation, targetRotation, Time.deltaTime * this.dampingFactor); if (this.setOnlyOnce && prevRotation.z > targetRotation.z - (targetRotation.z * 0.1)) { this.isActive = false; } } if (instrumentType == vehicleInstrumentType.BrakePressure) { float zValue = 70f; Quaternion prevRotation = gameObject.transform.localRotation; Quaternion targetRotation = Quaternion.Euler(0f, 0f, zValue); gameObject.transform.localRotation = Quaternion.Lerp(prevRotation, targetRotation, Time.deltaTime * this.dampingFactor); if (this.setOnlyOnce && prevRotation.z > targetRotation.z - (targetRotation.z * 0.1)) { this.isActive = false; } } if (instrumentType == vehicleInstrumentType.Temperature) { float zValue = 48f; Quaternion prevRotation = gameObject.transform.localRotation; Quaternion targetRotation = Quaternion.Euler(0f, 0f, zValue); gameObject.transform.localRotation = Quaternion.Lerp(prevRotation, targetRotation, Time.deltaTime * this.dampingFactor); if (this.setOnlyOnce && prevRotation.z > targetRotation.z - (targetRotation.z * 0.1)) { this.isActive = false; } } }