InputSystem icon indicating copy to clipboard operation
InputSystem copied to clipboard

Get simple "Face to Cursor" back to work

Open ManuelRauber opened this issue 7 years ago • 4 comments

Hi,

I've a simple Update function:

private void Update()
{
    Debug.Log($"{Camera.ScreenToWorldPoint(Input.mousePosition)} || ${Camera.ScreenToWorldPoint(Mouse.current.position.ReadValue())}");
    WeaponMotor.FaceTo(Camera.ScreenToWorldPoint(Input.mousePosition));
}
// WeaponMotor
public void FaceTo(Vector2 faceTo)
{
    var position = transform.position;
    var zRotation = Mathf.Rad2Deg * Mathf.Atan2(
                        faceTo.y - position.y,
                        faceTo.x - position.x
                    );

    transform.rotation = Quaternion.Euler(0, 0, zRotation);
}

When using Camera.ScreenToWorldPoint(Input.mousePosition) the weapon will always face the cursor as expected. When using Camera.ScreenToWorldPoint(Mouse.current.position.ReadValue()) instead, the y-position is not correct.

Sample log entries:

image

X and Z positions are correct, but the Y position is not correct for the new input system.

Definition of the Input System:

image image

Do I have to do anything else to make it work correctly, or is this a bug?

ManuelRauber avatar Apr 10 '19 20:04 ManuelRauber

Mouse.position is expected to be equivalent to Input.mousePosition. So yup, that'd be a bug. What's the platform?

Rene-Damm avatar Apr 10 '19 20:04 Rene-Damm

Platform: macOS Unity: 2019.1.0f1 Input System Package Version: 0.2.6

ManuelRauber avatar Apr 10 '19 20:04 ManuelRauber

This issue happens mainly in Editor. The standalone build is not impacted for the most part, but if user switches between fullscreen and windowed mode, the X is different.

JiaUnity avatar Apr 13 '19 00:04 JiaUnity

Filed: https://issuetracker.unity3d.com/product/unity/issues/guid/1145645/ Closing.

JiaUnity avatar Apr 13 '19 00:04 JiaUnity