///////////////////////////////// public void EnableCruiseToTarget() { initialTargetDistance = Vector3.Distance(cruiseTarget.transform.position, transform.position); //cannot jump if distance is to small if (initialTargetDistance >= 100f) { cruisingToTarget = true; OnShipWarpEvent?.Invoke(true); GetComponent <CircleCollider2D>().enabled = false; StartCoroutine(EnableCruiseParticles()); } }
/// <summary> /// TODO: /// STOP CRUISE MID CRUISE /// STOP TARGET BUTTONS FROM BEING PRESSED WHILE CRUISING /// </summary> // Update is called once per frame void Update() { if (cruiseTarget != null && warpMove) { targetDistance = Vector3.Distance(cruiseTarget.transform.position, transform.position); if (targetDistance < 70f) { Camera.main.GetComponent <CameraController>().shakeCamera = false; //Arived at target warpMove = false; cruisingToTarget = false; this.transform.GetComponent <Rigidbody2D>().velocity = new Vector2(0, 0); GetComponent <CircleCollider2D>().enabled = true; StartCoroutine(DisableCruiseParticles()); OnShipWarpEvent?.Invoke(false); } ParticleSystem ps = CruiseAnim[1].GetComponent <ParticleSystem>(); var forceDir = ps.forceOverLifetime; float var = transform.GetComponent <Rigidbody2D>().velocity.sqrMagnitude; //var = Mathf.Clamp(var,1000f,7000000f); //EmissionDir var dir = cruiseTarget.transform.position - this.gameObject.transform.position; //forceDir.x = dir.y; //forceDir.y = dir.x; //forceDir.z = dir.z; speed2 = ValueConvert.Instance.getConvertedValue(var * 10); } if (cruisingToTarget) { LookAtCruiseTarget(); if (warpMove && targetDistance > 70f) { this.transform.GetComponent <Rigidbody2D>().AddRelativeForce(Vector2.right * Time.smoothDeltaTime * ((accel + addedAccel) * GetComponent <Rigidbody2D>().mass *((float)warpMultiplier + addedWarpMultiplier)), ForceMode2D.Force); } } }