Force mouse position? alternative?

Hi, I’ve seen simular questions posted before but with insuficient answer’s.

So this is for a First person adventure style game, i want to lock the cursor at the center of the Screen (place mouse pos and thenScreen.lockCursor). Mouse position is however read only so i can’t seem to figure out how to do this properly.

The reason for positioning the mouse and not just locking it is to use functions from MonoBehavior.OnMouse… for colliders while at the same time having the cursor constantly at the center of the screen.

So is positioning of the mouse from scripts possible and if not alternative solutions for center cursor with interaction for colliders would be appreciated.

You can always manually invoke the OnMouse methods. Can always do your own Raycast from any arbitrary screen point too.

Vector3 ray = Camera.main.ScreenPointToRay(new Vector3(200, 100, 0))//get the ray as though the mouse was located at 200x100
RaycastHit hit;

if (Physics.Raycast(ray, out hit)) 
{
	hit.transform.gameObject.SendMessage("OnMouseOver");
}

Thanks for the fast reply it solves my problem in an easy way and to the letter :slight_smile: