Exemplo n.º 1
0
 private void Awake()
 {
     rb            = GetComponent <Rigidbody>();
     rb.useGravity = false;
     fluxState     = FluxState.NotInFlux;
     animator      = GetComponentInChildren <Animator>();
 }
Exemplo n.º 2
0
    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;
        }
    }
Exemplo n.º 3
0
    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);
        }
    }
Exemplo n.º 4
0
    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());
    }