private void Reposition() { var currentVehicle = self.GetVehicle(); if (currentVehicle != null) { hudTransform.position = currentVehicle.vehicleRigidbody.transform.position; hudTransform.forward = Vector3.down; if (showPointer || showLicense) { GameObject cameraObject = GameObject.FindGameObjectWithTag("HighwayCam"); if (cameraObject != null) { var orbitController = cameraObject.GetComponent <OrbitCameraController>(); if (orbitController != null) { hudTransform.localRotation = Quaternion.Euler(orbitController.rightAngle, orbitController.upAngle, orbitController.forwardAngle); //hudTransform.LookAt(cameraObject.transform, cameraObject.transform.up); //hudTransform.forward = -hudTransform.forward; } } } hudTransform.position -= hudDistance * hudTransform.forward; } }
void Update() { CheckTarget(); var vehicle = targetVehicle?.GetVehicle(); if (vehicle != null) { float speedPercent = vehicle.currentTotalSpeed / vehicle.vehicleStats.maxForwardSpeed; var camerasCamera = followCamera.GetComponent <Camera>(); float lerpedOrtho = Mathf.Lerp(camerasCamera.orthographicSize, Mathf.Lerp(orthoMinSize, orthoMaxSize, speedPercent), Time.deltaTime * orthoLerp); camerasCamera.orthographicSize = lerpedOrtho; orthoPercent = (lerpedOrtho - orthoMinSize) / (orthoMaxSize - orthoMinSize); cameraMosaic.mosaicPercent = Mathf.Lerp(closeMosaicPercent, farMosaicPercent, orthoPercent); followCamera.target = vehicle.transform; followCamera.rightAngle = rightAngle; followCamera.upAngle = (rotateWithVehicle ? vehicle.vehicleRigidbody.transform.rotation.eulerAngles.y : 0) + upAngleOffset; if (speedGauge != null) { float rawDiff = vehicle.vehicleStats.maxForwardSpeed * MathHelpers.MPS_TO_KMH / (speedGauge.markCount + 0); int diff = Mathf.CeilToInt(rawDiff / 10) * 10; speedGauge.markDiff = diff; speedGauge.value = Mathf.Abs(vehicle.GetSpeedInKMH()) / speedGauge.lastMarkValue; } } }
private void ManageEffects() { Transform expectedParent = self.GetVehicle()?.transform; #region Scan EffectWrapper scanEffect = scanLineEffect; Vector3 scanScale = new Vector3(0.5f, 0.5f, GetScanDistance()); if (scanLevel > 0) { scanEffect = scanSphereEffect; scanScale = Vector3.one * GetScanDistance(); scanLineEffect?.SetShown(false); } else { scanSphereEffect?.SetShown(false); } if (scanEffect != null) { if (scanEffect.transform.parent != expectedParent) { scanEffect.transform.SetParent(expectedParent, false); } scanEffect.shownScale = scanScale; scanEffect.SetShown(scan); scanEffect.SetColor(CanScan ? Color.green : Color.red); } #endregion #region Capture if (captureEffect != null) { if (captureEffect.transform.parent != expectedParent) { captureEffect.transform.SetParent(expectedParent, false); } captureEffect.shownScale = Vector3.one * GetCaptureDistance(); captureEffect.SetShown(capture); captureEffect.SetColor(IsCapturing ? Color.green : Color.red); } #endregion }
private void Update() { viewButton.gameObject.SetActive((shownOptions & Options.viewButton) != 0); priceLabel.gameObject.SetActive((shownOptions & Options.valueLabel) != 0); licenseLabel.gameObject.SetActive((shownOptions & Options.licenseLabel) != 0); companyLabel.gameObject.SetActive((shownOptions & Options.viewType) != 0); typeLabel.gameObject.SetActive((shownOptions & Options.viewType) != 0); compassGameObject.SetActive((shownOptions & Options.viewCompass) != 0); priceLabel.text = "$" + bounty.reward; licenseLabel.text = bounty.carData.vehicleLicense; var bountyVehicleIndex = bounty.carData.vehicleIndex; var vehicle = vehicles.allVehicles[bountyVehicleIndex]; if (vehicle != null) { companyLabel.text = vehicle.vehicleStats.companyName; typeLabel.text = vehicle.vehicleStats.modelName; } if (compassRelativeTo != null) { var otherVehicle = compassRelativeTo.GetVehicle(); if (otherVehicle != null) { var minBountyDistance = BountyTracker.bountyTrackerInScene.GetMinDistance(); var maxBountyDistance = BountyTracker.bountyTrackerInScene.GetMaxDistance(); float bountyDistance = Mathf.Abs(bounty.position - otherVehicle.vehicleRigidbody.position.z); float percentDistance = (Mathf.Clamp(bountyDistance, minBountyDistance, maxBountyDistance) - minBountyDistance) / (maxBountyDistance - minBountyDistance); int signalIndex = Mathf.RoundToInt((1 - percentDistance) * (distanceGauge.Length - 1)); SetDistanceGaugeIndex(signalIndex); //Vector2 bountyPosition = new Vector2(0, bounty.position); //Vector2 compassDirection = bountyPosition - otherVehicle.vehicleRigidbody.position.xz(); //compass.localRotation = Quaternion.Euler(0, 0, Vector2.SignedAngle(Vector2.up, compassDirection)); } } }
private bool Capture() { bool isCapturing = false; if (capture) { //There's a bug where you can capture unspawned vehicles, should probably check if active in heirarchy. Needs more testing if (currentTarget != null) { float targetDistance = (currentTarget.GetVehicle().vehicleRigidbody.transform.position - self.GetVehicle().vehicleRigidbody.transform.position).magnitude; if (targetDistance <= GetCaptureDistance() / 2) { isCapturing = true; if (startCaptureTime < 0) { startCaptureTime = Time.time; } int currentCaptureTimeLevel = Mathf.Clamp(captureTimeLevel, 0, captureTimes.Length - 1); if (Time.time - startCaptureTime >= captureTimes[currentCaptureTimeLevel]) { BountyTracker.bountyTrackerInScene.Catch(currentTarget.GetCarability().license); Debug.Log("Captured " + currentTarget.GetCarability().license); //Caught isCapturing = false; } } } } if (!isCapturing) { startCaptureTime = -1; } return(isCapturing); }
void Update() { for (int i = 0; i < currentBounties.Length; i++) { var currentBounty = currentBounties[i]; if (currentBounty.driver != null) { if (((BotDriver)currentBounty.driver).fallen) { currentBounty.driver = null; } else { currentBounty.position = currentBounty.driver.GetVehicle().transform.position.z; } } else { var bountyHunterVehicle = bountyHunter.GetVehicle(); float bountyHunterPosition = 0; if (bountyHunterVehicle != null) { bountyHunterPosition = bountyHunterVehicle.transform.position.z; } if (Mathf.Abs(bountyHunterPosition - currentBounty.position) <= GetMinDistance()) { currentBounty.driver = carSpawner.SpawnBot(currentBounty.headingNorth, currentBounty.lane, true, 0, currentBounty.carData); } else { currentBounty.position = Mathf.Clamp(currentBounty.position + (currentBounty.headingNorth ? 1 : -1) * 10 * Time.deltaTime, bountyHunterPosition - GetMaxDistance(), bountyHunterPosition + GetMaxDistance()); } } } }
public BotDriver SpawnBot(bool spawnOnRight, int spawnIndex, bool setRandomSpeed = true, float speed = 0, CarData carData = null) { var roadPoints = rightRoadPoints; if (!spawnOnRight) { roadPoints = leftRoadPoints; } //Get vehicle speed relative to highway float vehicleToAdjustTrafficToHighwaySpeed = 0; if (driverToAdjustTrafficTo != null) { var vehicleToAdjustTrafficTo = driverToAdjustTrafficTo.GetVehicle(); if (vehicleToAdjustTrafficTo != null) { float percentDirection = vehicleToAdjustTrafficTo.vehicleRigidbody.velocity.normalized.PercentDirection(Vector3.forward); vehicleToAdjustTrafficToHighwaySpeed = vehicleToAdjustTrafficTo.currentTotalSpeed * percentDirection; } } //Switch spawn side depending on vehicle speed relative to highway int offsetIndex = 0; if (vehicleToAdjustTrafficToHighwaySpeed > speedLimit - maxLimitDeviation && spawnOnRight) { offsetIndex = halfRoadLaneCount; } else if (vehicleToAdjustTrafficToHighwaySpeed < -speedLimit + maxLimitDeviation && !spawnOnRight) { offsetIndex = halfRoadLaneCount; } Transform spawnPoint = roadPoints[offsetIndex + spawnIndex]; Transform[] targets = GetTargets(roadPoints, halfRoadLaneCount); if (setRandomSpeed) { speed = Random.Range(speedLimit - maxLimitDeviation, speedLimit + maxLimitDeviation); } currentSpawnedVehicleCount++; lastSpawn = Time.time; return(BotCars.Get <BotDriver>((bot) => { Color vehicleColor; int vehicleIndex; if (carData != null) { vehicleIndex = (int)carData.vehicleIndex; bot.GetCarability().license = carData.vehicleLicense; vehicleColor = carData.vehicleColor; } else { vehicleIndex = whiteListedVehicles[Random.Range(0, whiteListedVehicles.Length)].index; bot.GetCarability().RandomizeLicense(); vehicleColor = ColorPercentage.PickColor(randomVehicleColorOptions).color; } bot.Respawn(spawnPoint.position, spawnPoint.rotation, vehicleIndex, speed); var carAppearance = bot.GetCarAppearance(); if (carAppearance != null) { carAppearance.showSiren = false; carAppearance.color = vehicleColor; } bot.GetVehicle().vehicleHealth.SetPercent(1); bot.GetCarHUD().showLicense = false; bot.GetCarHUD().showPointer = false; bot.targets = targets; bot.currentTargetIndex = spawnIndex; bot.onFall += Bot_onFall; })); }
public void SetShownToModifying() { currentWhitelistIndex = System.Array.IndexOf(whitelist, modifying.GetVehicle().vehicleStats); SetShownVehicle(GetShownVehicleIndex()); }