コード例 #1
0
    //Before rendering a frame
    void Update()
    {
        if (this.transform.position.y < -50)
        {
            CheckPoint();
        }
        switch (state)
        {
        case State.DIRECTION:
            VisualDebug.DisableRenderer(VisualDebug.Vectors.GREEN, transform);
            VisualDebug.DisableRenderer(VisualDebug.Vectors.RED, transform);

            redArrow.gameObject.SetActive(true);
            text.text = "Angle: " + Mathf.Round(ang).ToString();

            // TIMER - ang
            if (increaseAngle)
            {
                ang += Time.deltaTime * turnSpeed;
                if (ang >= maxAngle)
                {
                    increaseAngle = false;
                }
            }
            else if (!increaseAngle)
            {
                ang -= Time.deltaTime * turnSpeed;
                if (ang <= -maxAngle)
                {
                    increaseAngle = true;
                }
            }
            if (InputManager.Space())
            {
                Quat rotate = Quat.AngleAxis(ang, (Vec3)this.transform.up);
                this.transform.rotation = (Quaternion)(rotate * (Quat)this.transform.rotation);
                redArrow.gameObject.SetActive(false);
                velocity    = minForce;
                state       = State.PROPULSION;
                previousPos = (Vec3)transform.position;
            }

            float angArrow    = ang;
            Quat  rotateArrow = Quat.AngleAxis(ang - 90, (Vec3)this.transform.forward * -1);
            redArrow.transform.rotation = (Quaternion)(rotateArrow * (Quat)this.transform.rotation);

            break;

        case State.PROPULSION:
            powerBar.gameObject.SetActive(true);
            text.text = "Force: " + Mathf.Round(velocity).ToString();

            // TIMER - FORCE
            if (increase)
            {
                velocity += Time.deltaTime * powerSpeed;
                if (velocity >= maxForce)
                {
                    increase = false;
                }
            }
            else if (!increase)
            {
                velocity -= Time.deltaTime * powerSpeed;
                if (velocity <= minForce)
                {
                    increase = true;
                }
            }
            powerBar.value = velocity;

            // INPUT
            if (InputManager.Space())
            {
                state    = State.STRINGS;
                grounded = false;
                powerBar.gameObject.SetActive(false);
                direction += (Vec3)transform.forward;
            }

            break;

        case State.STRINGS:
            direction = Physics_functions.Molla(direction, transform);
            state     = State.JUMP;
            break;

        case State.JUMP:
            if (!grounded)
            {
                transform.position = (Vector3)Physics_functions.TirParabolic(direction, this.transform);
                direction.y       -= 9.81f * Time.deltaTime;
            }
            VisualDebug.DrawVector(direction, VisualDebug.Vectors.GREEN, transform);
            break;

        case State.LANDING:

            Vec3 friction = Physics_functions.FrictionJump(direction, drag);
            VisualDebug.DrawVector(friction, VisualDebug.Vectors.RED, transform);
            //x = x0 + (v0 + Ft) * t
            direction += Physics_functions.TirParabolic(friction, transform) * Time.deltaTime;
            float aux = (direction * Time.deltaTime).Module();
            if (aux >= 0.0001f && (direction.z * Time.deltaTime) >= 0)
            {
                transform.position += transform.forward * aux;
            }
            else
            {
                state = State.DIRECTION;
                transform.rotation = (Quaternion)inicialRotation;
                direction          = auxVel;
            }
            break;

        default:
            break;
        }
    }
コード例 #2
0
    //Before rendering a frame
    void Update()
    {
        if (this.transform.position.y < -100)
        {
            CheckPoint();
        }
        switch (state)
        {
        case State.DIRECTION:
            VisualDebug.DisableRenderer(VisualDebug.Vectors.GREEN, transform);

            redArrow.gameObject.SetActive(true);
            text.text = "Angle: " + Mathf.Round(ang).ToString();

            // TIMER - ang
            if (increaseAngle)
            {
                ang += Time.deltaTime * turnSpeed;
                if (ang >= maxAngle)
                {
                    increaseAngle = false;
                }
            }
            else if (!increaseAngle)
            {
                ang -= Time.deltaTime * turnSpeed;
                if (ang <= -maxAngle)
                {
                    increaseAngle = true;
                }
            }
            if (InputManager.Space())
            {
                Quat rotate = Quat.AngleAxis(ang, (Vec3)this.transform.up);
                this.transform.rotation = (Quaternion)(rotate * (Quat)this.transform.rotation);
                redArrow.gameObject.SetActive(false);
                velocity    = minForce;
                state       = State.PROPULSION;
                previousPos = (Vec3)transform.position;
            }

            float angArrow    = ang;
            Quat  rotateArrow = Quat.AngleAxis(ang - 90, (Vec3)this.transform.forward * -1);
            redArrow.transform.rotation = (Quaternion)(rotateArrow * (Quat)this.transform.rotation);

            break;

        case State.PROPULSION:
            powerBar.gameObject.SetActive(true);
            text.text = "Force: " + Mathf.Round(velocity).ToString();

            // TIMER - FORCE
            if (increase)
            {
                velocity += Time.deltaTime * powerSpeed;
                if (velocity >= maxForce)
                {
                    increase = false;
                }
            }
            else if (!increase)
            {
                velocity -= Time.deltaTime * powerSpeed;
                if (velocity <= minForce)
                {
                    increase = true;
                }
            }
            powerBar.value = velocity;

            // INPUT
            if (InputManager.Space())
            {
                state    = State.STRINGS;
                grounded = false;
                powerBar.gameObject.SetActive(false);
                direction += (Vec3)transform.forward;
                //Vec3 endPos = Physics_functions.TrobarPosicioFinalTir((direction + (Vec3)this.transform.forward) * velocity, this.transform);
                //GameObject.Find("base").GetComponent<ENTICourse.IK.InverseKinematics>().target = endPos;
            }

            break;

        case State.STRINGS:
            direction = Physics_functions.Molla(direction, transform);
            state     = State.JUMP;
            break;

        case State.JUMP:
            if (!grounded)
            {
                transform.position = (Vector3)Physics_functions.TirParabolic(direction, this.transform);
                direction.y       -= 9.81f * Time.deltaTime;
                //endPos = Physics_functions.TrobarPosicioFinalTir(direction, (Vec3)this.transform.position);
            }
            VisualDebug.DrawVector(direction, VisualDebug.Vectors.GREEN, transform);
            break;

        case State.LANDING:
            Vec3 friction = Physics_functions.FrictionJump(direction, drag);
            VisualDebug.DrawVector(friction, VisualDebug.Vectors.RED, transform);
            direction += friction * Time.deltaTime;
            if (direction.x > 0.1f && direction.z > 0.1f)
            {
                transform.position += (Vector3)direction;
            }
            else
            {
                state = State.DIRECTION;
            }
            break;

        default:
            break;
        }
    }