Currently, I am dealing with the irregular movements (video) of the left and right trackballs/mice which are based on the x and y axis values from corresponding trackballs/mice.
These are the methods that are responsible for the movements
public void Update()
{
while (inputQueue.TryDequeue(out var val))
{
if (val.Header.Type == RawInputType.Mouse && val.Header.Device.ToInt32() == leftTrackballDeviceID)
{
float mouseX = val.Data.Mouse.LastX;
float mouseZ = -val.Data.Mouse.LastY;
UpdateCursorPosition(leftCursor, mouseX, mouseZ);
}
else if (val.Header.Type == RawInputType.Mouse && val.Header.Device.ToInt32() == rightTrackballDeviceID)
{
float mouseX = val.Data.Mouse.LastX;
float mouseZ = -val.Data.Mouse.LastY;
UpdateCursorPosition(rightCursor, mouseX, mouseZ);
Debug.Log("mouseX: " + mouseX + " mouseZ: " + mouseZ);
}
}
}
private void UpdateCursorPosition(GameObject cursor, float x, float z)
{
Vector3 currentPosition = cursor.transform.position;
currentPosition.x += x * cursorSpeed * Time.deltaTime;
currentPosition.z += z * cursorSpeed * Time.deltaTime;
cursor.transform.position = currentPosition;
}
Currently, I am don’t know what is happeing with my code. I want the cursors (red moving circles in the video) to just move over the keyboard buttons (such that it will always intersect a button when moving).I am working on a 3D VR project in Unity.Please help me to figure out the problem.