private void applyAttachment(RocketPartController rocketPart, Transform rocketPartTransform, Transform attachmentPoint) { rocketPartTransform.position = attachmentPoint.position; rocketPartTransform.parent = attachmentPoint.transform; rocketController.GetComponent <Rigidbody>().mass += rocketPart.part.weight; attachedRocketParts.Add(rocketPart); }
// Start is called before the first frame update void Start() { this.previousLerpRate = flightLerpRate; rocketRigidBody = rocket.GetComponent <Rigidbody>(); // Set the camera directly at the start SetCameraPosition(); }
public void GameStart() { RocketController player = ObjectPooler.PoolObject("Player").GetComponent <RocketController>(); playerController = player.GetComponent <PlayerController>(); player.gameObject.SetActive(true); player.transform.position = spawnpoint; player.SetActive(true); music.gameObject.SetActive(true); music.Play(); StartSpawnEvent(); gameStartTime = Time.time; CameraFollow.instance.SetTarget(player.transform); CameraFollow.instance.SetActive(true); }
void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.tag == "PowerUp" && nitroTank < 1f) { Destroy(other.gameObject); this.nitroTank += 1f; if (nitroTank > maxNitroTank) { nitroTank = maxNitroTank; } } if (other.gameObject.tag == "ResistancePowerUp" && lifePoints < 1000f) { Destroy(other.gameObject); this.lifePoints += 1000; if (lifePoints > maxLifePoints) { lifePoints = maxLifePoints; } } if (other.gameObject.tag == "InstantNitro") { Destroy(other.gameObject); this.instantNitroTimer = 5f; } if (other.gameObject.tag == "InstantSlowDown") { Destroy(other.gameObject); this.instantSlowDownTimer = 5f; } if (other.gameObject.tag == "Shield") { Destroy(other.gameObject); this.shieldTimer = 5f; gameObject.GetComponent <SpriteRenderer> ().color = Color.green; } if (other.gameObject.tag == "Switch") { Destroy(other.gameObject); this.switchControlsTimer = 5f; switchControls(); } if (other.gameObject.tag == "SwitchOpp") { Destroy(other.gameObject); if (tag == "Player") { GameObject Cop = GameObject.FindGameObjectWithTag("Cop"); if (Cop != null) { Cop.GetComponent <CarController> ().switchControls(); } } else if (tag == "Cop") { GameObject.FindGameObjectWithTag("Player").GetComponent <CarController> ().switchControls(); } } if (other.gameObject.tag == "Rocket" && !hasRocket) { Destroy(other.gameObject); hasRocket = true; GameObject Rocket = GameObject.Instantiate(Resources.Load("RocketObject") as GameObject); RC = Rocket.AddComponent <RocketController> (); RC.Car = this; Physics2D.IgnoreCollision(RC.GetComponent <Collider2D> (), GetComponent <Collider2D> ()); } if (other.gameObject.tag == "Cheatsheet" && this.cheatsheetsCaught < MapController.nCheatsheets && !isCop) { Destroy(other.gameObject); this.cheatsheetsCaught++; if (this.cheatsheetsCaught == MapController.nCheatsheets) { MapController.SpawnEnd(); } } if (other.gameObject.tag == "End" && !isCop) { end = true; this.GameOver(); } }
void Update() { if (playerControlled) { if (Input.GetKeyUp(pauseKey)) { if (isPaused) { isPaused = false; pauseGame.SetActive(false); Time.timeScale = 1; } else { isPaused = true; pauseGame.SetActive(true); Time.timeScale = 0; } } // Throttle controls else if (Input.GetKey(throttleKey)) { throttle = 1; } else if (Input.GetKey(brakeKey)) { throttle = -brakingConstant; } else { throttle = 0; } // Turning controls if (Input.GetKey(leftKey)) { if (turn <= 0) { turn = 1; } else if (turn < 50) { turn += 1.5f; } } else if (Input.GetKey(rightKey)) { if (turn >= 0) { turn = -1; } else if (turn > -50) { turn -= 1.5f; } } else { turn = 0; } // Handbrake control if (Input.GetKey(handbrakeKey)) { handbrake = 1; } else { handbrake = 0; } // Nitro control if (Input.GetKey(nitroKey) && nitroTank > 0.01f && throttle != 0) { nitro = 1; flames.enabled = true; if (flamesTimer <= 0) { if (flameSpriteSelector) { flames.sprite = flameSprite; flameSpriteSelector = !flameSpriteSelector; } else { flames.sprite = flameSprite2; flameSpriteSelector = !flameSpriteSelector; } flamesTimer = 0.2f; } else { flamesTimer -= Time.deltaTime; } flamesAudio.mute = false; } else { nitro = 0; flames.enabled = false; flamesAudio.mute = true; } if (Input.GetKey(rocketKey)) { if (hasRocket) { RC.Launch(); } } } else { //TODO AI implementation //transform.position = Vector2.MoveTowards(transform.position, Player.position, 100 * Time.deltaTime); //var dir = Player.position - transform.position; //var angle = (Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg) - 90; //transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward); throttle = 1; var dir = Player.position - transform.position; dir = transform.InverseTransformDirection(dir); var angle = (Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg); //Debug.Log(angle); if (angle > 90 || angle < -90) { turn = 50; } else if (angle > -90 && angle < 90) { turn = -50; } else { turn = 0; } } if (instantNitroTimer > 0) { instantNitroTimer -= Time.deltaTime; } if (instantSlowDownTimer > 0) { instantSlowDownTimer -= Time.deltaTime; } if (shieldTimer > 0) { shieldTimer -= Time.deltaTime; if (shieldTimer <= 0) { gameObject.GetComponent <SpriteRenderer> ().color = Color.white; } } if (switchControlsTimer > 0) { switchControlsTimer -= Time.deltaTime; if (switchControlsTimer <= 0) { switchControls(); } } if (immunityTimer > 0) { immunityTimer -= Time.deltaTime; if (immunityTimer <= 0) { gameObject.GetComponent <SpriteRenderer> ().color = Color.white; } } if (!hasRocket && rocketBlitz) { if (rocketBlitzTimer > 0) { rocketBlitzTimer -= Time.deltaTime; } else { hasRocket = true; GameObject Rocket = GameObject.Instantiate(Resources.Load("RocketObject") as GameObject); RC = Rocket.AddComponent <RocketController> (); RC.Car = this; Physics2D.IgnoreCollision(RC.GetComponent <Collider2D> (), GetComponent <Collider2D> ()); rocketBlitzTimer = rocketBlitzInterval; } } }