Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        //Player Dismounts Dragon
        if (Input.GetKeyDown(KeyCode.E))
        {
            Player.transform.position = this.transform.position + new Vector3(10f, 10f, 10f);
            //Enable Player Camera
            PlayerCam.enabled = true;
            //Disable Dragon Camera
            CarCam.enabled = false;
            //Enable Projectile Shooter
            Player.GetComponent <ProjectileShooter>().enabled = true;
            //Enable Player Controller Script
            Player.GetComponent <PlayerController>().enabled = true;
            //Disable Dragon Controller Script
            this.enabled = false;
            //Re-enable gravity
            this.GetComponent <Rigidbody>().useGravity = true;
        }

        //Check if player wants to sprint
        speed = Input.GetKey(KeyCode.LeftShift) ? 30f : 15f;

        //Calculate movement velocity as a 3D vector
        float xMov = Input.GetAxisRaw("Horizontal");
        float zMov = Input.GetAxisRaw("Vertical");

        Vector3 movHorizontal = transform.right * xMov;
        Vector3 movVertical   = transform.forward * zMov;

        //Final movement vector
        Vector3 velocity = (movHorizontal + movVertical).normalized * speed;

        //Apply movement
        motor.Move(velocity);

        //Calculate rotation as a 3D vector (turning around)
        float yRot = Input.GetAxisRaw("Mouse X");

        Vector3 rotation = new Vector3(0f, yRot, 0f) * lookSensitivity;

        //Apply rotation
        motor.Rotate(rotation);

        //Calculate camera as a 3D vector (turning around)
        float xRot = Input.GetAxisRaw("Mouse Y");

        Vector3 cameraRotation = new Vector3(xRot, 0f, 0f) * lookSensitivity;

        //Apply rotation
        motor.RotateCamera(cameraRotation);
    }
Esempio n. 2
0
    /////////////////////////////////////////
    void Update()
    {
        if (PauseMenu.IsOn)
        {
            if (Cursor.lockState != CursorLockMode.None)
            {
                Cursor.lockState = CursorLockMode.None;
            }

            motor.Move(0f, 0f);
            motor.Rotate(0f);
            motor.Tilt(0f);

            return;
        }

        if (Cursor.lockState != CursorLockMode.Locked)
        {
            Cursor.lockState = CursorLockMode.Locked;
        }

        //calculate movement velocity as a 3D vector
        float steerwheel = Input.GetAxis("Horizontal");
        float accelerate = Input.GetAxis("Vertical");
        float _torque    = maxTorque * accelerate;
        float _steer     = steerwheel * maxSteerAngle;

        //apply movement
        motor.Move(_torque, _steer);

        //Animate movement
        animator.SetFloat("ForwardVelocity", accelerate);

        //calculate rotation as a 3d vector
        float _yRot          = Input.GetAxisRaw("Mouse X");
        float _rotationspeed = -_yRot * gunsensitivity;

        //apply rotation
        motor.Rotate(_rotationspeed);

        //calculate tilt as a 3d vector
        float _xRot      = Input.GetAxisRaw("Mouse Y");
        float _tiltspeed = _xRot * gunsensitivity;

        //apply tilt
        motor.Tilt(_tiltspeed);
        /////////////////////////////////////////////////////

        //calculate thruster force
        Vector3 _thrusterforce = Vector3.zero;

        if (Input.GetButton("Jump") && thrusterFuelAmount > 0f)
        {
            thrusterFuelAmount -= thrusterFuelBurnSpeed * Time.deltaTime;

            if (thrusterFuelAmount > 0.01f)
            {
                _thrusterforce = Vector3.up * thrusterforce;
            }
        }
        else
        {
            thrusterFuelAmount += thrusterFuelRegenSpeed * Time.deltaTime;
        }

        thrusterFuelAmount = Mathf.Clamp(thrusterFuelAmount, 0f, 1f);

        //apply thruster force
        motor.ApplyThruster(_thrusterforce);
    }