Get simple "Face to Cursor" back to work
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:
X and Z positions are correct, but the Y position is not correct for the new input system.
Definition of the Input System:
Do I have to do anything else to make it work correctly, or is this a bug?
Mouse.position is expected to be equivalent to Input.mousePosition. So yup, that'd be a bug. What's the platform?
Platform: macOS Unity: 2019.1.0f1 Input System Package Version: 0.2.6
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.
Filed: https://issuetracker.unity3d.com/product/unity/issues/guid/1145645/ Closing.