So I am updating the controls to my game to support the controller. But I realized that I do not know how to move the cursors position with the axis of the controller. The only way I could think about doing this is by making a fake cursor and moving that instead, is this the only option?
So if I were to make a new cursor, how would I get a raycast from the camera to the new UI Image in world space? Like would use:
Ray ray = Camera.main.ScreenPointToRay(Cursor.transform.position);
This draws a line from the camera to the element, but doesn’t point into the world like if I were to use Input.MousePosition.
Seems to be unless you want to have your end user use 3rd party software ( big nope usually but I’ve noticed steam controller mode behave as such I thought )
Dummy target it is… I’m in the same boat it seems.
It would probably make the most sense to have a GameObject and a Vector3 for this.
The GameObject will only be a visual cue, where you’ll need a billboarded shader to display a fake mouse cursor (unless you choose to do something fancier).
The Vector3, meanwhile, is your actual cursor position, driven directly by Input.mousePosition or shifted by controller input otherwise.
// After determining whether to use mouse or controller input...
if(usingMouseInput)
{
cursorPos = Input.mousePosition;
}
else if(usingControllerInput)
{
cursorPos += new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0) * cursorSpeed;
cursorPos.x = Mathf.Clamp(cursorPos.x, 0, Screen.width - 1);
cursorPos.y = Mathf.Clamp(cursorPos.y, 0, Screen.height - 1);
}
cursorObj.transform.position = Camera.main.ScreenToWorldPoint(cursorPos);