Recreate the delta of Input.GetAxis("MouseX") -> mousePosition.x or Event.current.m..

Hi

I still stuck on my touchscreen problem since a long time now.

I tried to change all the parameters in the drivers of the touchscreen but it doesn’t change anything. So I need to script that.

So basically here is the situation:

  • The GUIs works fine.

  • Anything with Input.GetAxis(“Mouse X/Y”) doesn’t work.

  • The Input.mousePosition.x/y or the Event.current.mousePosition.x/y are recognized.

  • I need to re-create the same Input that the GetAxis, wich if i did understood well is a delta position, and that by using Input.mousePosition or Event.current.mousePosition

  • I’m rotating around an object by using that script: (All C#)

 //--------------Rotation--------------------

            //Check if the mouse button is on 

            
            if (Input.GetMouseButton(0))
             {

            //Set the AmtToRotate

            xDeg = -(Screen.width / 2 - Input.mousePosition.x) * SpeedCoef * xSpeed;
            yDeg = (Screen.height / 2 - Input.mousePosition.y) * SpeedCoef * ySpeed;


            // Make sure that the yDeg is still in the Y limits
            yDeg = ClampAngle(yDeg, yMinLimit, yMaxLimit);

            //Use the AmtToRotate to rotate the camera
            desiredRotation = Quaternion.Euler(yDeg, xDeg, 0);
            currentRotation = transform.rotation;
            //Add a damping
            rotation = Quaternion.Slerp(currentRotation, desiredRotation, Time.deltaTime * RotDamp);
            transform.rotation = rotation;

             }
             if (!Input.GetMouseButton(0)) //-->finish the lerp when !mouse0
             {
                 currentRotation = transform.rotation;
                 rotation = Quaternion.Slerp(currentRotation, desiredRotation, Time.deltaTime * RotDamp);
                 transform.rotation = rotation;
             }

As you can see at the moment I’m using that:

xDeg = -(Screen.width / 2 - Input.mousePosition.x) * SpeedCoef * xSpeed;
            yDeg = (Screen.height / 2 - Input.mousePosition.y) * SpeedCoef * ySpeed;

which as long as I don’t take my finger off the screen seems to work fine. But the major problem is there. When I touch the screen(click not drag) the camera rotates to go to that position because of the mousePosition.x = a certain number on that position same for y so I can’t “add” a rotation to my previous one by take off my finger and drag again(i’m not sure it’s really clear). So everytime a touch the screen the camera rotate to the position gave by the position of my screen and It shouldn’t move when I’m not dragging

I thought a lot about it and I think that I need to do that in two part:

  1. I need to create an equation which calculate the X,Y translation of my finger. So something like onMouseButtonDown the position = (Xa,Ya), onMouseButton position = (Xb,Yb) Then Translation delta = (Xb - Xa, Yb - Ya).

  2. Add that new X, Y to my Rotation each frame.

I think the logic is good now (really correct me if i’m wrong) but I’m having trouble to transcribe that
If some one as an idea or did that previously ?

I’ll post my research here

Really hope that I can finish that asap, I’m getting sick of it :smile:

Thank’s for the help

BooBi

up

Don’t know back then, but at least now with Unity 3.4 I solved the same issue simply using Touch’s deltaPosition, as follows:

		float pointer_x = Input.GetAxis("Mouse X");
		float pointer_y = Input.GetAxis("Mouse Y");
		if (Input.touchCount > 0)
		{
			pointer_x = Input.touches[0].deltaPosition.x;
			pointer_y = Input.touches[0].deltaPosition.y;
		}
1 Like

has there been a solution with this? I’m using an ELO touchscreen and have been having the same issues. I’ve thought about your suggested first suggested delta solution though haven’t tried it out yet.

Such an old thread to respond to. The deltaPosition gives the amount in X and Y since the last frame’s mouse position. In the case of an Android or iOS, it will give you the first finger position.

Cawas’ assesment is correct though, using the GetAxis and then querying the touches is the best way to go. This way you can test things on your PC without having to load and install it on your phone or ipad.

My issue is that the ELO touchscreen I’m using doesn’t work properly with the getaxis function and it doesn’t actually return the delta values properly and it isn’t multitouch and this isn’t intended for android or iOS.

I’m trying something like this

  	if (Input.GetMouseButtonDown(0)){
   		
   		pressX = x = Input.mousePosition.x;
    	pressY = y = Screen.height - Input.mousePosition.y; // Inverted Y
   	}
   		
     if (Input.GetMouseButton(0)   ){ 
        var fMouseX :float =  Input.mousePosition.x;
        var fMouseY : float  = Screen.height - Input.mousePosition.y; // Inverted Y
   
        x += ((fMouseX - pressX) - x) / xSpeed ;
        y -= ((fMouseY - pressY) + y) / ySpeed  ;

        y = ClampAngle(y, yMinLimit, yMaxLimit);

        var rotation = Quaternion.Euler(y, x, 0);
        var position = rotation * Vector3(0.0, 0.0, -distance) + target.position;

        
        transform.rotation = rotation;
        transform.position = position;
        
      
    }