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:
-
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).
-
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
Thank’s for the help
BooBi