Log in or register to post comments

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

October 27, 2018 - 6:24pm #7

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?

October 29, 2018 - 1:31pm #6

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

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

November 26, 2019 - 3:48am #5

Use LeanTouch package from Unity Store

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 28, 2020 - 5:54pm #3

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?

April 2, 2021 - 2:18pm #2

Hi i'm beginner , can you please give more details about this assets and how to do the touch events please? if there will be any videos i will be greatfull. thank you

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

April 13, 2021 - 2:09am #1

Hi @isamalhassan,

As mentioned by medabit, in our Core Sample app available on the Unity asset store, there is scene Ground Plane in which we demo exactly this behaviour.

Link to our Core Sample app: https://assetstore.unity.com/packages/templates/packs/vuforia-core-samples-99026

Thank you.

Vuforia Engine Support

 

Log in or register to post comments