Project for disabled son.

Ok so I need a little help with a control issue. I am using an eye gaze tracker to create mouse input on the screen for my son whom has cerebral palsey. This works well however when linking this control to an object in unity it moves just like you would expect, using the drag and drop function I can click drag and drop. So there’s my issue I am looking for away to simply drag. No clicking, no dropping just simply fix an object so that it moves left or right with the cursor of the mouse. It’s a simple game designed to teach children with disabilities that through looking at the left or right of the screen that the object will follow.

Please if there is a script to lock an object so it moves as the cursor moves I would be greatful

Hello @Slim1278,

In Unity we use Axis information to get Input from the user, in your case the eye gaze tracker, When you say “left and right” i see you are talking about 2D space, Let’s do something like this depending if you are using 3d objects on a orthogonal camera for fake the 2D, or using the unity’s GUI on a real 2d Canvas:

  1. Orthogonal 2D: You could put a background plane with collider, then put a script on the object you want to move that moves its own transform to the hit.point position of a raycast to a mousePosition.
  2. Real 2D: Or you could just use Unity’s built in GUI and do the same as above but easier.

First Option (3D World Space Cube Example):
I will call the Object you want to move: “Cube”, for better understanding purposes

  1. Create and Add a C# Script to the Cube you want to move and remove the object collision component, call the script “FollowMouse”;

  2. Create on the scene a background Plane with collision

  3. Open up that script you just created and paste the following on it:

            //Define two variables
    	Ray ray;
    	RaycastHit hit;
    
           
    	void Update () {
                    //Create a ray from the X,Y screen mouse Position on the Camera
    		ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    
                    //Make a raycast from the ray to a distance 'this case:  50f' and          output a raycasthit.
    
    		if(Physics.Raycast(ray, out hit, 50f)){
                           //If the raycast hit something, "in this case our background plane", move this "cube" transform to that hit.point
    			this.transform.position = hit.point;
    		}
    	}
    

You should get something like this:
54812-cubeexample.jpg

As the Second Option using Canvas Unity GUI System you could do something like this, i dont have the time right now to get an example going on right now, but i really hope this helps you or gets you in the correct rail.

Don’t thanks me, Say hi to your son.

-Leo

Source: Unity Docs: Get Axis , Docs: Input MousePosition

Hi @Leoo,
Yer my plan was to use a 3D scene with a 3D object but restrict movement to only one axis, so as Callum’s control improves changes can be made to the control method to allow for 3D movement.

I will endeavour to try these two options you have suggested tonight thank you Darren