private void Awake() { rb = GetComponent <Rigidbody>(); rb.useGravity = false; fluxState = FluxState.NotInFlux; animator = GetComponentInChildren <Animator>(); }
private void FluxHighwayUpdate() { rb.position = Quaternion.AngleAxis(fluxSpeed * Time.fixedDeltaTime * fluxDirection, Vector3.forward) * transform.position; if (spaceInput) { // Exit flux highway. onExitFlux.Invoke(); shipAngleInput = 0; rb.isKinematic = false; fluxExitTime = Time.time; EventManager.instance.FluxHighwayStateChanged(false); fluxState = FluxState.NotInFlux; rb.velocity = -transform.position.normalized * fluxHighwayExitSpeed; } }
private void FluxHighwayCheck() { if (fluxState == FluxState.InFlux) { return; } if (Time.time - fluxExitTime < fluxCooldown) { return; } if (transform.position.magnitude > fluxHighwayHeight) { // Enter flux highway. onEnterFlux.Invoke(); fluxCurrentSpeed = rb.velocity.magnitude; fluxEnterTime = Time.time; fluxState = FluxState.InTransition; EventManager.instance.FluxHighwayStateChanged(true); fluxDirection = (int)Mathf.Sign(shipAngleInput); } }
private void FixedUpdate() { // Add gravity if (fluxState == FluxState.NotInFlux) { rb.isKinematic = false; Vector2 toCore = -transform.position; rb.AddForce(toCore.normalized * gravityForce); if (isBoosting) { rb.AddForce(transform.up * movementForce * boostMultiplier, ForceMode.Force); } else { rb.AddForce(transform.up * movementForce * movementInput, ForceMode.Force); } } else if (fluxState == FluxState.InTransition) { float shipAngleInputGoal = fluxDirection * 90; Debug.Log(shipAngle); shipAngle = Mathf.MoveTowards(shipAngle, shipAngleInputGoal, 90 / fluxTransitionTime * Time.deltaTime); fluxCurrentSpeed = Mathf.MoveTowards(fluxCurrentSpeed, fluxSpeed, fluxSpeed / fluxTransitionTime * Time.deltaTime); if (Time.time - fluxEnterTime > fluxTransitionTime) { Debug.Log("shipAngle"); fluxState = FluxState.InFlux; } } else { shipAngleInput = fluxDirection * 90; shipAngle = shipAngleInput; } rb.rotation = Quaternion.Euler(0f, 0f, shipAngle + CalcSurfaceNormalAngle()); }