private void Update() { if (isDead) { return; } //all of this code points the blue arrow in the directino of the nearest landing pod if (Time.time - GameManager.instance.worldStartTime - lastEnergyArrowUpdateTime >= energyArrowUpdateDelay) { lastEnergyArrowUpdateTime = Time.time - GameManager.instance.worldStartTime; if (landingPodSpawner.currentPods.Count == 0) { if (nearByEnergyArrow.gameObject.activeSelf) { nearByEnergyArrow.gameObject.SetActive(false); closestLandingPodIndex = -1; nearbyEnergyArrowAngle = -1000f; } return; } else { if (!nearByEnergyArrow.gameObject.activeSelf) { nearByEnergyArrow.gameObject.SetActive(true); } } int closestPodIndex = -1; float closestPodDistance = 1000f; for (int i = 0; i < landingPodSpawner.currentPods.Count; i++) { if (landingPodSpawner.currentPods[i] == null) { continue; } if (Vector3.SqrMagnitude(landingPodSpawner.currentPods[i].transform.position - rover.transform.position) < closestPodDistance * closestPodDistance) { closestPodDistance = Vector3.Distance(landingPodSpawner.currentPods[i].transform.position, rover.transform.position); closestPodIndex = i; } } if (closestPodIndex == -1) { nearByEnergyArrow.gameObject.SetActive(false); return; } closestLandingPodIndex = closestPodIndex; LandingPod closestPod = landingPodSpawner.currentPods[closestPodIndex]; if (closestPod == null) { Debug.LogError("closest landing pod was null"); } Vector3 dirToPod = (closestPod.transform.position - rover.transform.position).normalized; Vector3 projectedDirection = Vector3.ProjectOnPlane(dirToPod, rover.transform.up); float ang = Vector3.SignedAngle(projectedDirection, rover.transform.forward, rover.transform.up); nearbyEnergyArrowAngle = ang; nearByEnergyArrow.eulerAngles = new Vector3(0, 0, ang); } }
// Update is called once per frame void FixedUpdate() { velocity = spacecraftRB.velocity.magnitude * 10f; if (velocity > 200f) //-----Maksymalna predkosc { spacecraftRB.drag = drag; } else { spacecraftRB.drag = defaultDrag; } if (Input.GetKeyDown(KeyCode.R)) { Destroy(gameObject); } if (Input.GetKey(KeyCode.Space) && GameManager.isPlayable && !outOfFuel) { spacecraftRB.AddRelativeForce(Vector3.up.normalized * force); ps.Play(); } else { ps.Stop(); } if (Input.GetKey(KeyCode.LeftArrow) && GameManager.isPlayable) { spacecraftRB.AddRelativeTorque(Vector3.forward * rotationForce); } if (Input.GetKey(KeyCode.RightArrow) && GameManager.isPlayable) { spacecraftRB.AddRelativeTorque(-Vector3.forward * rotationForce); } if (rayOne.touchdownOne && rayTwo.touchdownTwo && goodLanding) { GameManager.isPlayable = false; goodLanding = false; LP_lights = GameObject.Find("LandingController").GetComponent <LandingPod>(); LP_lights.touchdown = true; GameManager.lvlPassed = true; } }
public void SpawnPod() { if (isEnabled) { Vector3 planetCenterToLocation = roverTransform.position + Random.onUnitSphere * maxRoverPodInitialDistance; Vector3 planetCenterToLocationOnPlanet = planetCenterToLocation.normalized * (planetRadius); Vector3 spawnLocation = planetCenterToLocation + (planetCenterToLocationOnPlanet - planetCenterToLocation); while (Vector3.SqrMagnitude(spawnLocation - roverTransform.position) <= minRoverPodInitialDistance * minRoverPodInitialDistance) { planetCenterToLocation = roverTransform.position + Random.onUnitSphere * maxRoverPodInitialDistance; planetCenterToLocationOnPlanet = planetCenterToLocation.normalized * (planetRadius); spawnLocation = planetCenterToLocation + (planetCenterToLocationOnPlanet - planetCenterToLocation); } spawnLocation += planetCenterToLocation.normalized * 10f; LandingPod pod = Instantiate(landingPodPrefab, spawnLocation, Quaternion.identity, landingPodsParent.transform).GetComponent <LandingPod>(); pod.Initialize(); pod.SetSpawnInfo(currentPods.Count); currentPods.Add(pod); } }