Mouse Delta problem ... I'm stumped

Hi,
I’m trying to use what I’ve learned so far to find (and display for testing) the position of my mouse so I can use that position to trigger certain actions of my transform. I’m not sure what all of the math involved is to accomplish this fully.

What I have so far works, for the intended purpose, but it’s not exactly what I’m looking for. I’m trying to “quadrant” the screen to 4 sections with the center being zero. To the left of Xcenter I need zero (xCenter) to -1 (Left edge if screen), to the right of Xcenter, equals positive 1 (Right edge of screen). The same for Y except above Ycenter, positive 1(Top edge of screen) and below Ycenter -1(Bottom edge of screen).

As close as I can get is zero to 1 using this:

using UnityEngine;
using System.Collections;
 
public class MousePositionTest : MonoBehaviour
{
 // These help find the center of the screen. It's not exactly what I'm trying to find, but works for what I need it for.
 // I'm trying to get the center to 0 and then -1 to the left of xcenter and positive 1 to the right of xcenter, also 
 // -1 below ycenter and positive 1 above ycenter. The purpose is to allow particular "action" of the ship depending 
 // on the mouse screen position when the mouse button is pressed for Yaw.
	private float xCenter = (Screen.width / 2); 
	private float yCenter = (Screen.height / 2);
	private Vector3 mousePos;
	private Vector2 mouseDeltaPos;
 
	void Update()
	{
		mousePos = Input.mousePosition;
		mouseDeltaPos = new Vector2((mousePos.x / xCenter) / 2, (mousePos.y / yCenter) / 2);		
	}

	void FixedUpdate()
	{
		if(Input.GetMouseButton(1)  mouseDeltaPos.x > .55f)
		{
		    //do something						
		}
		else if(Input.GetMouseButton(1)  mouseDeltaPos.x < .45f)
		{
		    //do something				
		}
		else
		    return;
	}

	
	public void OnGUI()
	{		
		GUI.Label(new Rect(10, 10, 150,50), "X_Position: " + mouseDeltaPos.x);	
		GUI.Label(new Rect(10, 30, 150, 50), "Y_Position: " + mouseDeltaPos.y); 		
	}
}

I have to use .5 as my center, where mouseDeltaPos.x = 0 equals the left side of screen, mouseDeltaPos.x = 1 equals the right side of the screen.

How do I get?

mouseDeltaPos.x = -1 equal left side of screen
mouseDelta.x = 0 center
mouseDeltaPos.x = 1 equal the right side of screen

Doing a google search for mouse screen delta, mouse position, how to (insert any of what I’ve asked) yields no answers to anything I have questions about.

I’ve spent hours looking and can’t find anything related to my questions.

Any help or insight would be appreciated greatly.

So to be clear you’re looking for a piece of code that will give you the mouse position in the range of [-1.0 … 1.0] on both axes.

Why not just replace your existing Update with the following:

	void Update()
	{
		mousePos = Input.mousePosition;

//get mouse position as a percentage of screen space
//the components of this vector will be in the range [0.0 .. 1.0] with 0 being left most or bottom most
		Vector2 mousePosPercent = new Vector2 ((mousePos.x/Screen.width),(mousePos.y/Screen.height));

//now double the percentage to allow the 2 full percentage ranges (percentage in left and right sides or bottom and top)
//this results in each component being in the range [0.0 .. 2.0]
		mousePosPercent *= 2f;

//now normalize the 2 ranges on the center by subtracting 1 from both components yielding mouseDeltaPos
//this will now have the range for each component being [-1.0 .. 1.0]
		mouseDeltaPos = mousePosPercent - Vector2.one;		
	}

You could collapse all that to one line as follows:

	void Update()
	{
		mousePos = Input.mousePosition;
		mouseDeltaPos = (new Vector2 ((mousePos.x/Screen.width),(mousePos.y/Screen.height)) * 2f) - Vector2.one;		
	}

Now if mouseDeltaPos.x is less than 0 it is on the left of the screen, and with y less than 0 it is on the bottom.

Thank you, I guess my math skills are lacking quite a bit. I could only figure half of it out.