// 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);
    }
Example #2
0
    private void FixedUpdate()
    {
        if (!canMove)
        {
            return;
        }

        // pass the input to the car!
        float h         = Input.GetAxis("Horizontal");
        float v         = Input.GetAxis("Vertical");
        float handbrake = Input.GetAxis("Jump");

        m_Car.Move(h, v, v, handbrake);
    }
    public void MoveDidApplyHandbrake()
    {
        //Arrange
        CarMotor car      = new CarMotor();
        var      movement = GetMovementMock();

        car.SetCarMovementInterface(movement);

        //Act
        car.Move(0, 0, 0, 1);

        //Assert
        movement.Received().ApplyHandBrake(Arg.Any <float>()); // we should see the velocity being reset
    }
    public void MoveAddDownforce()
    {
        //Arrange
        CarMotor car      = new CarMotor();
        var      movement = GetMovementMock();

        car.SetCarMovementInterface(movement);
        float dF = (float)GetInstanceField(typeof(CarMotor), car, "m_Downforce");

        //Act
        car.Move(0, 0, 0, 1);

        //Assert
        movement.Received().AddDownForce(dF); // we should see the velocity being reset
    }
    public void MoveClamping()
    {
        //Arrange
        CarMotor car = new CarMotor();
        var movement = GetMovementMock();
        car.SetCarMovementInterface(movement);
        car.InitializeCarMotor(new Vector3(0, 0, 0), 25f, 0.7f, 0.5f, 2500f, 500f, 100f, 1f, 0.3f, 20000f);

        //Act
        car.Move(0, 25, -25, 0);

        //Assert
        Assert.AreEqual(1f, car.AccelInput);
        Assert.AreEqual(-1f, -car.BrakeInput);
    }
    public void MoveClamping()
    {
        //Arrange
        CarMotor car      = new CarMotor();
        var      movement = GetMovementMock();

        car.SetCarMovementInterface(movement);
        car.InitializeCarMotor(new Vector3(0, 0, 0), 25f, 0.7f, 0.5f, 2500f, 500f, 100f, 1f, 0.3f, 20000f);

        //Act
        car.Move(0, 25, -25, 0);

        //Assert
        Assert.AreEqual(1f, car.AccelInput);
        Assert.AreEqual(-1f, -car.BrakeInput);
    }
    public void MoveApplyDrive()
    {
        //Arrange
        CarMotor car = new CarMotor();
        var movement = GetMovementMock();
        car.SetCarMovementInterface(movement);
        car.InitializeCarMotor(new Vector3(0, 0, 0), 25f, 0.7f, 0.5f, 2500f, 500f, 100f, 1f, 0.3f, 20000f);
        float t = (float)GetInstanceField(typeof(CarMotor), car, "m_CurrentTorque");
        float accel = 0.5f;

        //Act
        car.Move(0, accel, 0, 0);

        //Assert
        movement.Received().ApplyMotorTorque(accel * t / 4); // t in this case is the total torque over all 4 wheels so divide by 4
    }
    public void MoveRotateTires()
    {
        //Arrange
        CarMotor car = new CarMotor();
        var movement = GetMovementMock();
        car.SetCarMovementInterface(movement);
        car.InitializeCarMotor(new Vector3(0, 0, 0), 25f, 0.7f, 0.5f, 2500f, 500f, 100f, 1f, 0.3f, 20000f);
        float maxSteerAngle = (float)GetInstanceField(typeof(CarMotor), car, "m_MaximumSteerAngle");
        float steering = 0.5f;

        //Act
        car.Move(steering, 0, 0, 0);

        //Assert
        movement.Received().RotateFrontTires(steering * maxSteerAngle);
    }
    public void MoveApplyDrive()
    {
        //Arrange
        CarMotor car      = new CarMotor();
        var      movement = GetMovementMock();

        car.SetCarMovementInterface(movement);
        car.InitializeCarMotor(new Vector3(0, 0, 0), 25f, 0.7f, 0.5f, 2500f, 500f, 100f, 1f, 0.3f, 20000f);
        float t     = (float)GetInstanceField(typeof(CarMotor), car, "m_CurrentTorque");
        float accel = 0.5f;

        //Act
        car.Move(0, accel, 0, 0);

        //Assert
        movement.Received().ApplyMotorTorque(accel * t / 4); // t in this case is the total torque over all 4 wheels so divide by 4
    }
Example #10
0
    public void MoveRotateTires()
    {
        //Arrange
        CarMotor car      = new CarMotor();
        var      movement = GetMovementMock();

        car.SetCarMovementInterface(movement);
        car.InitializeCarMotor(new Vector3(0, 0, 0), 25f, 0.7f, 0.5f, 2500f, 500f, 100f, 1f, 0.3f, 20000f);
        float maxSteerAngle = (float)GetInstanceField(typeof(CarMotor), car, "m_MaximumSteerAngle");
        float steering      = 0.5f;

        //Act
        car.Move(steering, 0, 0, 0);

        //Assert
        movement.Received().RotateFrontTires(steering * maxSteerAngle);
    }
Example #11
0
    public void MoveCheckForWheelSpinEndTrail()
    {
        //Arrange
        CarMotor car      = new CarMotor();
        var      movement = GetMovementMock();

        movement.GetWheelColliderForwardSlip(Arg.Any <int>()).Returns(0);  // less then slip limit
        movement.GetWheelColliderSidewaysSlip(Arg.Any <int>()).Returns(0); // less then slip limit
        car.SetCarMovementInterface(movement);
        float slipLimit = 0.3f;

        car.InitializeCarMotor(new Vector3(0, 0, 0), 25f, 0.7f, 0.5f, 2500f, 500f, 100f, 1f, slipLimit, 20000f);

        //Act
        car.Move(0, 0, 0, 1);

        //Assert
        movement.Received(4).EndSkidTrail(Arg.Any <int>()); // we should the skid trail ending 4 times
    }
Example #12
0
    public void MoveCheckForWheelSpinTireSmoke()
    {
        //Arrange
        CarMotor car      = new CarMotor();
        var      movement = GetMovementMock();

        movement.GetWheelColliderForwardSlip(Arg.Any <int>()).Returns(1);  // more then slip limit
        movement.GetWheelColliderSidewaysSlip(Arg.Any <int>()).Returns(1); // more then slip limit
        car.SetCarMovementInterface(movement);
        float slipLimit = 0.3f;

        car.InitializeCarMotor(new Vector3(0, 0, 0), 25f, 0.7f, 0.5f, 2500f, 500f, 100f, 1f, slipLimit, 20000f);

        //Act
        car.Move(0, 0, 0, 1);

        //Assert
        movement.Received(4).EmitTireSmoke(Arg.Any <int>()); // we should the tire smoke emitted 4 times
    }
Example #13
0
    public void MoveCapSpeed()
    {
        //Arrange
        CarMotor car      = new CarMotor();
        var      movement = GetMovementMock();

        movement.GetRigidbodyVelocity().Returns(100f); // this will return a velocity magnitude equal to our top speed variable
        car.SetCarMovementInterface(movement);
        float topSpeed = 100f;

        car.InitializeCarMotor(new Vector3(0, 0, 0), 25f, 0.7f, 0.5f, 2500f, 500f, topSpeed, 1f, 0.3f, 20000f);
        float mphConst = (float)GetInstanceField(typeof(CarMotor), car, "k_MphConst");

        //Act
        car.Move(0, 1, 0, 0);

        //Assert
        movement.Received().SetRigidbodyVelocity(topSpeed / mphConst); // we should see the velocity being reset
    }
Example #14
0
    public void MoveCheckForWheelSpinTireSmoke()
    {
        //Arrange
        CarMotor car = new CarMotor();
        var movement = GetMovementMock();
        movement.GetWheelColliderForwardSlip(Arg.Any<int>()).Returns(1); // more then slip limit
        movement.GetWheelColliderSidewaysSlip(Arg.Any<int>()).Returns(1); // more then slip limit
        car.SetCarMovementInterface(movement);
        float slipLimit = 0.3f;
        car.InitializeCarMotor(new Vector3(0, 0, 0), 25f, 0.7f, 0.5f, 2500f, 500f, 100f, 1f, slipLimit, 20000f);

        //Act
        car.Move(0, 0, 0, 1);

        //Assert
        movement.Received(4).EmitTireSmoke(Arg.Any<int>()); // we should the tire smoke emitted 4 times
    }
Example #15
0
    public void MoveDidApplyHandbrake()
    {
        //Arrange
        CarMotor car = new CarMotor();
        var movement = GetMovementMock();
        car.SetCarMovementInterface(movement);

        //Act
        car.Move(0, 0, 0, 1);

        //Assert
        movement.Received().ApplyHandBrake(Arg.Any<float>()); // we should see the velocity being reset
    }
Example #16
0
    public void MoveCapSpeed()
    {
        //Arrange
        CarMotor car = new CarMotor();
        var movement = GetMovementMock();
        movement.GetRigidbodyVelocity().Returns(100f); // this will return a velocity magnitude equal to our top speed variable
        car.SetCarMovementInterface(movement);
        float topSpeed = 100f;
        car.InitializeCarMotor(new Vector3(0, 0, 0), 25f, 0.7f, 0.5f, 2500f, 500f, topSpeed, 1f, 0.3f, 20000f);
        float mphConst = (float)GetInstanceField(typeof(CarMotor), car, "k_MphConst");

        //Act
        car.Move(0, 1, 0, 0);

        //Assert
        movement.Received().SetRigidbodyVelocity(topSpeed/mphConst); // we should see the velocity being reset
    }
Example #17
0
    public void MoveCheckForWheelSpinEndTrail()
    {
        //Arrange
        CarMotor car = new CarMotor();
        var movement = GetMovementMock();
        movement.GetWheelColliderForwardSlip(Arg.Any<int>()).Returns(0); // less then slip limit
        movement.GetWheelColliderSidewaysSlip(Arg.Any<int>()).Returns(0); // less then slip limit
        car.SetCarMovementInterface(movement);
        float slipLimit = 0.3f;
        car.InitializeCarMotor(new Vector3(0, 0, 0), 25f, 0.7f, 0.5f, 2500f, 500f, 100f, 1f, slipLimit, 20000f);

        //Act
        car.Move(0, 0, 0, 1);

        //Assert
        movement.Received(4).EndSkidTrail(Arg.Any<int>()); // we should the skid trail ending 4 times
    }
Example #18
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);
    }
Example #19
0
    public void MoveAddDownforce()
    {
        //Arrange
        CarMotor car = new CarMotor();
        var movement = GetMovementMock();
        car.SetCarMovementInterface(movement);
        float dF = (float)GetInstanceField(typeof(CarMotor), car, "m_Downforce");

        //Act
        car.Move(0, 0, 0, 1);

        //Assert
        movement.Received().AddDownForce(dF); // we should see the velocity being reset
    }