コード例 #1
0
    void Update()
    {
        float moveHorizontal = controller.GetAxis("Right", "Horizontal");
        float moveVertical   = controller.GetAxis("Right", "Vertical");

        Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);

        rb.AddForce(movement * speed);

        //transform.Translate (speed * Input.GetAxis ("Horizontal") * Time.deltaTime, 0.0f, speed * Input.GetAxis ("Vertical") * Time.deltaTime);
    }
コード例 #2
0
    void Update()
    {
        var input = new Vector2((xAxis.Invert ? -1.0f : 1.0f) * ControllerInput.GetAxis((uint)Controller, xAxis.Range, xAxis.Axis),
                                (zAxis.Invert ? -1.0f : 1.0f) * ControllerInput.GetAxis((uint)Controller, zAxis.Range, zAxis.Axis));
        // Get the input vector from keyboard or analog stick
        var directionVector = new Vector3(input.x, 0, input.y);

        if (directionVector != Vector3.zero)
        {
            // Get the length of the directon vector and then normalize it
            // Dividing by the length is cheaper than normalizing when we already have the length anyway
            var directionLength = directionVector.magnitude;
            directionVector = directionVector / directionLength;

            // Make sure the length is no bigger than 1
            directionLength = Mathf.Min(1, directionLength);

            // Make the input vector more sensitive towards the extremes and less sensitive in the middle
            // This makes it easier to control slow speeds when using analog sticks
            directionLength = directionLength * directionLength;

            // Multiply the normalized direction vector by the modified length
            directionVector = directionVector * directionLength;
        }

        // Apply the direction to the CharacterMotor
        motor.inputMoveDirection = transform.rotation * directionVector;
        motor.inputJump          = ControllerInput.GetButton((uint)Controller, JumpButton);
    }
コード例 #3
0
        public void Update(ControllerInput input)
        {
            if (target != null)
            {
                switch (type)
                {
                case AxisType.Joystick:
                    target.localPosition = m_CachedVector3 + new Vector3(input.GetAxis(axes[0]) * maxValue, input.GetAxis(axes[1]) * maxValue, 0.0f);
                    break;

                case AxisType.Trigger:
                    target.localRotation = Quaternion.AngleAxis(m_CachedVector3.x + input.GetAxis(axes[0]) * maxValue, Vector3.right);
                    break;
                }
            }
        }
コード例 #4
0
    //Moves the arm.
    void Movement(string name, int max, int min)
    {
        //Extend arm
        if (controller.GetAxis(name, "Vertical") > 0)
        {
            anim.Play("Robot Arm");
            if (counter < 120)

            {
                anim.SetFloat("Direction", 1.0f);
                counter += 1;
            }
            else
            {
                anim.SetFloat("Direction", 0.0f);
            }
        }
        else
        {
            if (counter > 0)
            {
                anim.SetFloat("Direction", -1.0f);
                counter -= 1;
            }
            else
            {
                anim.SetFloat("Direction", 0.0f);
            }
        }

        //Rotate arm
        if (!(arm.transform.rotation.eulerAngles.y > max && controller.GetAxis(name, "Horizontal") > 0) &&
            !(arm.transform.rotation.eulerAngles.y < min && controller.GetAxis(name, "Horizontal") < 0) && counter == 0)
        {
            counter = 0;
            arm.transform.Rotate(new Vector3(0, controller.GetAxis(name, "Horizontal"), 0));
        }
    }
コード例 #5
0
    public void Update(float dt)
    {
        float currentInput = input.GetAxis(trigger);

        currentInput   = Mathf.MoveTowards(currentApplied, currentInput, 9f * dt);
        currentApplied = currentInput;

        if (birdControl.DEBUG_ENABLE_KEYBOARD)
        {
            const float MOV_AMOUNT = 0.2f;

            if (trigger == ControllerAction.L2 && Input.GetKey(KeyCode.A))
            {
                _keyboardInput += MOV_AMOUNT;
            }
            if (trigger == ControllerAction.R2 && Input.GetKey(KeyCode.D))
            {
                _keyboardInput += MOV_AMOUNT;
            }

            currentInput    = _keyboardInput;
            _keyboardInput *= 0.9f;
        }

        shoulder.bone.localRotation = shoulder.initialLocalRotation * Quaternion.AngleAxis(Mathf.Lerp(-20f * sign, 0, currentInput), Vector3.up)
                                      * Quaternion.AngleAxis(Mathf.Lerp(20f * sign, 0, currentInput), Vector3.forward);


        wing_1.bone.localRotation = wing_1.initialLocalRotation * Quaternion.AngleAxis(Mathf.Lerp(-80f, 40f, currentInput), Vector3.right);


        wing_2.bone.localRotation = wing_2.initialLocalRotation * Quaternion.AngleAxis(Mathf.Lerp(50f * sign, 0, currentInput), Vector3.forward)
                                    * Quaternion.AngleAxis(Mathf.Lerp(-10f, 0, currentInput), Vector3.right);

        wing_2.bone.localScale = new Vector3(1, Mathf.Lerp(0.7511079f, 1f, currentInput), 1f);


        wing_2_f.bone.localRotation = wing_2_f.initialLocalRotation * Quaternion.AngleAxis(Mathf.Lerp(-10f, 0f, currentInput), Vector3.forward);

        wing_2_f.bone.localScale = new Vector3(1, Mathf.Lerp(0.5f, 1f, currentInput), 1f);


        wing_3.bone.localRotation = wing_3.initialLocalRotation * Quaternion.AngleAxis(Mathf.Lerp(-5f, 10f, currentInput), Vector3.right);
    }
コード例 #6
0
    public static PoseData CalculateFromController(ControllerInput controller)
    {
        PoseData result = new PoseData();

        result.leftWing  = controller.GetAxis(ControllerAction.L2);
        result.rightWing = controller.GetAxis(ControllerAction.R2);
        result.head.x    = controller.GetAxis(ControllerAction.LEFT_STICK_X);
        result.head.y    = controller.GetAxis(ControllerAction.LEFT_STICK_Y);
        result.tail.x    = controller.GetAxis(ControllerAction.RIGHT_STICK_X);
        result.tail.y    = controller.GetAxis(ControllerAction.RIGHT_STICK_Y);

        return(result);
    }
コード例 #7
0
    void Update()
    {
        if (axes == RotationAxes.XAndY)
        {
            float inputX = ControllerInput.GetAxis((uint)controller, range, ControllerInput.Axis.X);
            if (invert)
            {
                inputX = -inputX;
            }
            float rotationX = transform.localEulerAngles.y + inputX * sensitivityX;

            float inputY = ControllerInput.GetAxis((uint)controller, range, ControllerInput.Axis.Y);
            if (invert)
            {
                inputY = -inputY;
            }
            rotationY += inputY * sensitivityY;
            rotationY  = Mathf.Clamp(rotationY, minimumY, maximumY);

            transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
        }
        else if (axes == RotationAxes.X)
        {
            float inputX = ControllerInput.GetAxis((uint)controller, range, ControllerInput.Axis.X);
            if (invert)
            {
                inputX = -inputX;
            }
            transform.Rotate(0, inputX * sensitivityX, 0);
        }
        else
        {
            float inputY = ControllerInput.GetAxis((uint)controller, range, ControllerInput.Axis.Y);
            if (invert)
            {
                inputY = -inputY;
            }
            rotationY += inputY * sensitivityY;
            rotationY  = Mathf.Clamp(rotationY, minimumY, maximumY);

            transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
        }
    }
コード例 #8
0
ファイル: Pose.cs プロジェクト: PinkRodeo/GGJ2016
	public static PoseData CalculateFromController(ControllerInput controller)
	{
		PoseData result = new PoseData ();

		result.leftWing = controller.GetAxis (ControllerAction.L2);
		result.rightWing = controller.GetAxis (ControllerAction.R2);
		result.head.x = controller.GetAxis (ControllerAction.LEFT_STICK_X);
		result.head.y = controller.GetAxis (ControllerAction.LEFT_STICK_Y);
		result.tail.x = controller.GetAxis (ControllerAction.RIGHT_STICK_X);
		result.tail.y = controller.GetAxis (ControllerAction.RIGHT_STICK_Y);

		return result;
	}
コード例 #9
0
	/// <summary>
	/// Gets the combined axis values in a single vector
	/// </summary>
	/// <returns>A 0 to 1 normalized value, where 0.5 is idle</returns>
	public Vector2 GetLeftStick()
	{
		return new Vector2((input.GetAxis(ControllerAction.LEFT_STICK_X) + 1) * 0.5f,
						   (input.GetAxis(ControllerAction.LEFT_STICK_Y) + 1) * 0.5f);
	}