public HoverCraftBase nearestAheadOf(Transform relativeTo) { spawnedList.RemoveAll(delegate(GameObject o) { return(o == null); }); HoverCraftBase toRet = null; float coneAhead = 35.0f; float nearestDistance = 300.0f; foreach (GameObject craft in spawnedList) { float angleTo = Quaternion.Angle(Quaternion.LookRotation(relativeTo.forward), Quaternion.LookRotation(craft.transform.position - relativeTo.position)); float distInFront = relativeTo.transform.InverseTransformPoint(craft.transform.position).z; if (distInFront > 5.0f && distInFront < nearestDistance && angleTo < coneAhead) { nearestDistance = distInFront; toRet = (HoverCraftBase)craft.GetComponent <PlayerDrive>(); if (toRet == null) { toRet = (HoverCraftBase)craft.GetComponent <EnemyDrive>(); } } } return(toRet); }
void OnTriggerEnter(Collider collInfo) { HoverCraftBase hcbScript = collInfo.GetComponentInParent <HoverCraftBase>(); if (hcbScript) { sprintRamming = true; // brief! will be overridden/forgotten on next AI update in 0.2-0.5 sec // Debug.Log(name + " attempting to ram " + collInfo.name); } }
// Update is called once per frame void LateUpdate() { if (forCraft == null) { if (isPlayerSoUseUI) { GameObject playerCraft = GameObject.Find("PlayerCraft(Clone)"); if (playerCraft) { forCraft = (HoverCraftBase)playerCraft.GetComponent <PlayerDrive>(); } } else { forCraft = (HoverCraftBase)GetComponent <EnemyDrive>(); } if (forCraft == null) { return; } } float distInFront; if (forCraft.sprintRamming == false) { forCraft.lockFocus = allEnemies.nearestAheadOf(transform); } if (forCraft.lockFocus != null) { distInFront = transform.InverseTransformPoint(forCraft.lockFocus.transform.position).z; } else { distInFront = -100.0f; } if (isPlayerSoUseUI) { if (distInFront > 0.0f) { lockBox.rectTransform.position = Camera.main.WorldToScreenPoint(forCraft.lockFocus.transform.position); if (lockBox.enabled == false) { lockBox.enabled = true; } } else if (isPlayerSoUseUI && lockBox.enabled) { lockBox.enabled = false; } } }
void LateUpdate() { if (useCarCollisionTuning) { return; } if (lockFocus != null && lockFocus.sprintRamming) // break if sprinting { lockFocus = null; } if (lockFocus == null) { sprintRamming = false; } if (sprintRamming) { timeSinceHookFired += Time.deltaTime; endPt = lockFocus.transform.position + Vector3.up * (-0.7f); float wasPercHookOut = percHookOut; percHookOut = Mathf.Min(timeSinceHookFired * 2.0f, 1.0f); if (wasPercHookOut < 1.0f && percHookOut >= 1.0f) { Vector3 posDiffNorm = (lockFocus.transform.position - transform.position).normalized; Vector3 sparkPt = endPt - posDiffNorm * 1.5f; GameObject.Instantiate(hookSparkPfxPrefab, sparkPt, Quaternion.LookRotation(posDiffNorm), lockFocus.transform); } if (cableHook.enabled == false) { cableHook.enabled = true; } } if (cableHook.enabled) { cableHook.SetPosition(0, transform.position + Vector3.up * (-0.6f)); Vector3 hookPt = transform.position * (1.0f - percHookOut) + endPt * percHookOut; cableHook.SetPosition(1, hookPt); } }
void OnCollisionEnter(Collision collInfo) { HoverCraftBase hcbScript = collInfo.collider.GetComponentInParent <HoverCraftBase>(); if (hcbScript) { float otherSpeed = hcbScript.totalActualSpeedNow; float selfSpeed = totalActualSpeedNow; if (selfSpeed > otherSpeed) { hcbScript.ChangeHealth(-1); Vector3 pushVect = hcbScript.bodyToTilt.transform.position - bodyToTilt.transform.position; float bangBackPowerWinner = 10.0f; float bangBackPowerDamaged = 20.0f; float bangBackAngleMax = 60.0f; pushVect = pushVect.normalized; hcbScript.bangBackMomentum = pushVect * bangBackPowerDamaged; bangBackMomentum = -pushVect * bangBackPowerWinner; hcbScript.bodyToTilt.Rotate(Random.insideUnitCircle * bangBackAngleMax); hcbScript.sprintRamming = false; bodyToTilt.Rotate(Random.insideUnitCircle * bangBackAngleMax); sprintRamming = false; GameObject sparkGO = GameObject.Instantiate(hookSparkPfxPrefab, (transform.position + hcbScript.transform.position) * 0.5f, Quaternion.identity); sparkGO.transform.localScale *= 2.0f; GameObject snowGO = GameObject.Instantiate(snowPuffPfxPrefab, (transform.position + hcbScript.transform.position) * 0.5f, Quaternion.identity); snowGO.transform.localScale *= 3.35f; /* * pushVect = Quaternion.AngleAxis(90.0f, Vector3.up) * pushVect; * hcbScript.bodyToTilt.Rotate(pushVect,70.0f); * bodyToTilt.Rotate(pushVect,-70.0f);*/ } } }
void ResetStaticsAndLoadScene(int sceneIndex) { EnemyDrive.ResetStatics(); HoverCraftBase.ResetStatic(); SceneManager.LoadScene(sceneIndex); }
// Update is called once per frame void Update() { Tick(); float stunnedBangMagnitude = 4.0f; if (bangBackMomentum.magnitude > stunnedBangMagnitude) { turnControl = gasControl = 0.0f; } RaycastHit rhInfo; if (sprintRamming && useCarCollisionTuning == false) { if (lockFocus == null) { sprintRamming = false; } else { Vector3 posDiff = (lockFocus.transform.position - transform.position); if (Physics.Raycast(transform.position + Vector3.up * 2.0f, // give a little headroom posDiff, out rhInfo, posDiff.magnitude, ignoreVehicleLayerMask)) { lockFocus = null; // LOS blocked, break line sprintRamming = false; } else if (percHookOut < 1.0f) { float angFacingNow = Mathf.Atan2(transform.forward.z, transform.forward.x); Vector3 vectToFocus = lockFocus.transform.position - transform.position; float angFacingFocus = Mathf.Atan2(vectToFocus.z, vectToFocus.x); turnControl = Mathf.DeltaAngle(angFacingNow, angFacingFocus) * -3.0f; } else { Vector3 heightMatched = lockFocus.transform.position; heightMatched.y = transform.position.y; transform.LookAt(heightMatched); turnControl = 0.0f; float distTo = (lockFocus.transform.position - transform.position).magnitude; if (distTo < 14.0f) { lockFocus.SendMessage("Destruction"); lockFocus = null; sprintRamming = false; } } } } transform.Rotate(Vector3.up, turnControl * 80.0f * Time.deltaTime); momentum *= 0.94f; momentum += transform.forward * bodyToTilt.forward.y * Time.deltaTime * -7.0f; momentum += transform.right * bodyToTilt.right.y * Time.deltaTime * -10.0f; float impendingCrashDetectionNormal = 1.0f; /*if(Physics.Raycast(transform.position, //Removed while working on AI * transform.forward, out rhInfo, 10.0f*shipScale, ignoreVehicleLayerMask)) { * //Debug.DrawLine(rhInfo.point, transform.position, Color.red); * //Debug.DrawLine(rhInfo.point, rhInfo.point+rhInfo.normal*3.0f, Color.green); * impendingCrashDetectionNormal = rhInfo.normal.y; * }*/ if (impendingCrashDetectionNormal < 0.1f // || OutOfDome(transform.position + transform.forward * gasControl * 10.0f) ) { momentum *= 0.5f; enginePower = -1.0f; sprintRamming = false; } else { if ((useCarCollisionTuning ? sprintRamming : HaveEnemyHooked())) { enginePower = ramBoostMult; } else { enginePower = gasControl; } //None of this will ever be called due to commenting out the part above } momentum += transform.forward * enginePower * 9.0f * Time.deltaTime; Vector3 newPos = transform.position; newPos += momentum; boostDrawing = enginePower > 0.2f; float trailWidth = (Mathf.Max(enginePower, 0.0f)) * 0.5f; for (int i = 0; i < trList.Length; i++) { trList[i].widthMultiplier = trailWidth; } float engineLight = (Mathf.Max(enginePower, 0.0f)) * 2.0f; for (int i = 0; i < engineLights.Length; i++) { engineLights[i].intensity = engineLight; } float minHeightHere = heightUnderMe(newPos) + 0.9f; timeSinceLastPuff += Time.deltaTime; if (transform.position.y < minHeightHere) { if (timeSinceLastPuff > timeBetweenPuffs) { GameObject.Instantiate(snowPuffPfxPrefab, transform.position, Quaternion.identity, transform); timeSinceLastPuff = 0.0f; } } newPos.y = Mathf.Max(newPos.y, minHeightHere); newPos = ForceIntoDome(newPos); totalActualSpeedNow = ((newPos - transform.position).magnitude) / Time.deltaTime; transform.position = newPos; }
protected override void Tick() { if (Input.GetKey(KeyCode.C)) { Camera.main.fieldOfView = 77.0f; Camera.main.transform.position = domeCenter + Vector3.up * domeRadius * 1.3f; Camera.main.transform.LookAt(domeCenter); return; } if (Input.GetKeyDown(KeyCode.Space)) { sprintRamming = !sprintRamming; targetFOV = ((useCarCollisionTuning ? sprintRamming : HaveEnemyHooked()) ? 77.0f : 60.0f); } float cameraK = 0.8f; Camera.main.fieldOfView = cameraK * Camera.main.fieldOfView + (1.0f - cameraK) * targetFOV; Vector3 projectedCamPos = transform.position - transform.forward * 4.5f * shipScale + Vector3.up * 0.85f * shipScale; projectedCamPos = HoverCraftBase.ForceIntoDome(projectedCamPos); Vector3 vectDiff = projectedCamPos - transform.position; Ray rayLine = new Ray(transform.position, vectDiff); RaycastHit rhInfo; if (Physics.Raycast(rayLine, out rhInfo, vectDiff.magnitude, HoverCraftBase.ignoreVehicleLayerMask)) { Camera.main.transform.position = rhInfo.point; } else { Camera.main.transform.position = projectedCamPos; } Camera.main.transform.localRotation = Quaternion.AngleAxis( (HaveEnemyHooked() ? 2.0f : 0.15f) * Random.Range(-1.0f, 1.0f) * gasControl, Vector3.forward); if (sprintRamming == false) { turnControl = Input.GetAxis("Horizontal"); gasControl = Input.GetAxis("Vertical"); } else if (useCarCollisionTuning) { turnControl = Input.GetAxis("Horizontal"); if (Input.GetAxis("Vertical") < 0.0f) { sprintRamming = false; } } if (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.A)) { //AkSoundEngine.PostEvent(turnLeftID, gameObject); GetComponent <AkTriggerTurnLeft>().TurningLeft(); } if (Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.D)) { //AkSoundEngine.PostEvent(turnRightID, gameObject); GetComponent <AkTriggerTurnRight>().TurningRight(); } float tiltAmt = Mathf.DeltaAngle(0.0f, bodyToTilt.eulerAngles.x); float maxTiltDetected = 30.0f; tiltAmt = Mathf.Clamp(tiltAmt, -maxTiltDetected, maxTiltDetected) / -maxTiltDetected; AkSoundEngine.SetRTPCValue("Player_Velocity", enginePower / ramBoostMult); AkSoundEngine.SetRTPCValue("Player_Tilt", tiltAmt); }