Log in or register to post comments

How to rotate an object along all 3 axes with finger swipe?

October 27, 2018 - 6:24pm #1

I'm working on a simple AR Vuforia application. How can I implement the rotation of an object along all three axes with one finger swipe?

The code I'm currently using has one bug: the rotation of the object depends on its local axes. For example, if I look at the object from the front, everything works as it should, but if I look at the object from the back side, the finger swipe upwards makes it rotate downwards and vice versa.

Here is this script:

public float rotSpeed = 30f;

void OnMouseDrag()

{

float rotX = Input.GetAxis("Mouse X")*rotSpeed*Mathf.Deg2Rad;

float rotY = Input.GetAxis("Mouse Y")*rotSpeed*Mathf.Deg2Rad;

transform.Rotate(Vector3.up, -rotX);

transform.Rotate(Vector3.right, -rotY);

}



But this is not what I need, how can I rotate the object according to the finger swipe direction regardless of the angle from which I look at it?

How to rotate an object along all 3 axes with finger swipe?

November 28, 2020 - 5:54pm #5

Hello, I don't know how to write scripts. I only write scripts. For me, this lotate script is a necessary script. Could you make this script for me? My email is

. I beg you.

How to rotate an object along all 3 axes with finger swipe?

May 7, 2020 - 2:25am #4

Hello everyone.

This works nice regardless of your object's rotation, and regardless of your camera position relative to the object:

public float rotSpeed = 30f;

void OnMouseDrag()

{

    float rotX = Input.GetAxis("Mouse X") * rotSpeed;

    float rotY = Input.GetAxis("Mouse Y") * rotSpeed;

    Camera camera = Camera.main;

    Vector3 right = Vector3.Cross(camera.transform.up, transform.position - camera.transform.position);

    Vector3 up = Vector3.Cross(transform.position - camera.transform.position, right);

    transform.rotation = Quaternion.AngleAxis(-rotX, up) * transform.rotation;

    transform.rotation = Quaternion.AngleAxis(rotY, right) * transform.rotation;

}

Make sure your camera has the "MainCamera" tag, or assign the camera externally if necessary.

Thank you.

How to rotate an object along all 3 axes with finger swipe?

November 26, 2019 - 3:48am #3

Use LeanTouch package from Unity Store

How to rotate an object along all 3 axes with finger swipe?

October 29, 2018 - 1:31pm #2

Hello,

The Vuforia Ground Plane sample app in our Core Samples demonstrates how to use touch events to move augmentations. These are available for free on the Unity Asset Store.

Thanks,

Vuforia Engine Support

Log in or register to post comments