예제 #1
0
 // Update is called once per frame
 void Update()
 {
     horizontal = Input.GetAxis("Horizontal");
     vertical   = Input.GetAxis("Vertical");
     motor.setSteering(horizontal);
     motor.setMotor(vertical);
 }
    // Update is called once per frame
    void Update()
    {
        // Clamp z rotation between -30 and 30 degrees
        Vector3 rot = transform.eulerAngles;

        if (rot.z > 30)
        {
            rot -= new Vector3(0, 0, 1) * Time.deltaTime * 20;
            transform.eulerAngles = rot;
        }
        else if (rot.z < -30)
        {
            rot += new Vector3(0, 0, 1) * Time.deltaTime * 20;
            transform.eulerAngles = rot;
        }

        if (commandTimer < maxCommandTimer)
        {
            commandTimer += Time.unscaledDeltaTime;

            if (lastTimer <= swervingMaxTime / 2 && commandTimer >= swervingMaxTime / 2)
            {
                if (lastCommand == Command.SWERVE_LEFT)
                {
                    motor.setSteering(1f);
                }
                else if (lastCommand == Command.SWERVE_RIGHT)
                {
                    motor.setSteering(-1f);
                }
            }

            lastTimer = commandTimer;
        }
        else
        {
            if (motorSpeed < 1.0f)
            {
                motorSpeed += speedUpRate;
            }
            motor.setMotor(motorSpeed);
            motor.setSteering(0f);
        }
    }