Search Unity

Testing a simple mouse position using the new Input System

Discussion in 'Input System' started by Muhamad_Faizol, Dec 30, 2018.

  1. Muhamad_Faizol

    Muhamad_Faizol

    Joined:
    Jan 21, 2017
    Posts:
    47
    OS : Linux (Fedora 29)
    Unity's version : 2018.3f2

    Hi all,

    I just tested a simple script attached to an object in a new scene but the result is totally off. The cube's position is not as the click's position and seems to be flying all over the place.

    Code (csharp):
    1.  
    2. void Update()
    3. {
    4.    if(Mouse.current.leftButton.wasPressedThisFrame)
    5.    {
    6.      Ray ray = Camera.main.ScreenPointToRay(Mouse.current.position.ReadValue());
    7.      RaycastHit hit;
    8.      if(Physics.Raycast(ray, out hit))
    9.      {
    10.        transform.position = hit.point;
    11.      }
    12.    }
    13. }
    14.  
    Is the above is the right way to test the new Input System's mouse position?

    Thanks.

    Cheers,
     
    sampyash likes this.
  2. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Looks like the Linux backend isn't reporting mouse positions in the right coordinate space. I've filed a ticket here. Looking at your script, that'd be expected to work fine.