Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We’re making changes to the Unity Runtime Fee pricing policy that we announced on September 12th. Access our latest thread for more information!
    Dismiss Notice
  3. Dismiss Notice

Input System delta[mouse] add values on click

Discussion in 'Input System' started by antony_morar, Mar 22, 2020.

  1. antony_morar

    antony_morar

    Joined:
    Nov 7, 2017
    Posts:
    12
    Hi Im trying to make a first person controller with Character controller and the new input system. One problem appear in delta[mouse] or delta[pointer]is the the Vector2 returns a value when i press any button of the mouse, this cause that the player camera rotate a little bit. Example:


    These are my actions:


    And this is my code:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.InputSystem;
    5.  
    6. [RequireComponent (typeof(CharacterController))]
    7. public class PlayerCharacterController : MonoBehaviour
    8. {
    9.     private Vector2 moveInput = Vector2.zero;
    10.     private Vector2 rotationInput = Vector2.zero;
    11.     private float cameraVerticalAngle = 0f;
    12.     // ****** Character Controler
    13.     private CharacterController characterController;
    14.     // ****** Input Actions
    15.     private PlayerInputActions inputActions;
    16.  
    17.     [Header("Refrerences")]
    18.     [Tooltip("Reference for the main camare used for the player")]
    19.     public Camera playerCamera;
    20.  
    21.     [Header("General")]
    22.     [SerializeField] private float walkSpeed = 12f;
    23.     [SerializeField] private float gravityDownForce = 20f;
    24.  
    25.     [Header("Movement")]
    26.     [SerializeField] private float speedOnGround;
    27.  
    28.     [Header("Rotation")]
    29.     [SerializeField] private float rotationSpeed = 60f;
    30.  
    31.     [Header("Jump")]
    32.     [SerializeField] private float jumpForce;
    33.  
    34.     private void Awake()
    35.     {
    36.         characterController = GetComponent<CharacterController>();
    37.         inputActions = new PlayerInputActions();
    38.         inputActions.PlayerControlls.Move.performed += ctx => moveInput = ctx.ReadValue<Vector2>();
    39.         inputActions.PlayerControlls.CameraMove.performed += ctx => rotationInput = ctx.ReadValue<Vector2>();
    40.     }
    41.  
    42.     private void Start()
    43.     {
    44.         //Cursor.lockState = CursorLockMode.Locked;
    45.     }
    46.  
    47.     private void Update()
    48.     {
    49.         Move(inputActions.PlayerControlls.Move.ReadValue<Vector2>());
    50.         Look(inputActions.PlayerControlls.CameraMove.ReadValue<Vector2>());
    51.     }
    52.  
    53.     private void Move(Vector2 direction)
    54.     {
    55.         if (direction.sqrMagnitude < 0.05)
    56.             return;
    57.         float scaledMoveSpeed = walkSpeed * Time.deltaTime;
    58.         Vector3 move = Quaternion.Euler(0, transform.eulerAngles.y, 0) * new Vector3(direction.x, 0, direction.y);
    59.         transform.position += move * scaledMoveSpeed;
    60.     }
    61.  
    62.     private void Look(Vector2 rotate)
    63.     {
    64.         if (rotationInput.sqrMagnitude < 0.05)
    65.             return;
    66.  
    67.         // ****** Limit the X rotation force amount
    68.         rotate.x = Mathf.Clamp(rotate.x, -10f, 10f);
    69.         rotate.y = Mathf.Clamp(rotate.y, -10f, 10f);
    70.  
    71.         // ****** Delta rotation in Quaternions
    72.         rotationInput.x = rotate.x * rotationSpeed * Time.deltaTime;
    73.         rotationInput.y = rotate.y * rotationSpeed * Time.deltaTime;
    74.  
    75.         // ****** Vertical rotation in degrees
    76.         cameraVerticalAngle += rotationInput.y;
    77.         cameraVerticalAngle = Mathf.Clamp(cameraVerticalAngle, -70f,70f);
    78.  
    79.         transform.Rotate(0, rotationInput.x, 0);
    80.         playerCamera.transform.localRotation = Quaternion.Euler(-cameraVerticalAngle, 0f, 0f);
    81.     }
    82.  
    83.  
    84.     private void OnEnable()
    85.     {
    86.         inputActions.Enable();
    87.     }
    88.  
    89.     private void OnDisable()
    90.     {
    91.         inputActions.Disable();
    92.     }
    93. }
    94.  
     
    MakMiles likes this.
  2. MakMiles

    MakMiles

    Joined:
    Mar 28, 2018
    Posts:
    1
    I have the same issue. Looks like a bug.
     
  3. Fox_GAMING

    Fox_GAMING

    Joined:
    May 7, 2018
    Posts:
    12
    I don't even see Mouse Delta as an Option...
     
  4. MadMaxed

    MadMaxed

    Joined:
    Oct 20, 2015
    Posts:
    1
    Ran into same issue but it looks like the Action Type has to be Pass Through for the delta option (and others like position) to pop up.
     
  5. chris_gamedev

    chris_gamedev

    Joined:
    Feb 10, 2018
    Posts:
    34
    I have the same issue as @antony999k and @MakMiles.

    I wanted to include a very simple reproduction case and hopefully get a member of the Unity dev team to provide some input.

    I've also got this video which demonstrates the issue.



    The amount of drift and direction is actually somewhat random and intermittent, and sometimes you need to wiggle the mouse around or look in a different direction before it happens.

    But from the point in the video where you see the
    Vector2(-7, 0)
    being logged in the console, this is being caused by me clicking.

    You can check in the code in the attached project but to be clear, the console logs relate to the mouse delta values from the input system, I don't log
    Vector2.zero
    and only log values that are different from the last value.

    What this means is the console logs are demonstrating that the mouse isn't actually moving (if it were there'd be logs every frame with different values) and the simple action of clicking is registering a mouse delta value.

    If it helps the video is taken on a MacBook Pro running macOS 11 and the built-in touchpad. I haven't had the opportunity to test with Windows 10 yet.

    This is with Unity 2020.3.15f2 and Input System 1.0.2.
     

    Attached Files:

  6. valentin56610

    valentin56610

    Joined:
    Jan 22, 2019
    Posts:
    144
    Hello
    I do have the exact same issue as of Unity 2020.3.33f1 ...
    I can't continue my game anymore as this destroyed my entire camera system ... please anyone fix this....
     
  7. valentin56610

    valentin56610

    Joined:
    Jan 22, 2019
    Posts:
    144
    ashtorak likes this.