Sharing Gesture Code

Recently a unity user asked me to help him with getting gestures working for navigating around a planet. As to be able to pinch in and out for zooming, flicking for orbiting and twisting for orienting (planet gyrating).

I created a unity project for the community to be able to do exactly this. Hope this helps as a starter for developers that want to have a similar interface or want to learn some gesture handling.

Let me know what you guys think. Enjoy!

Get the code here:
http://www.rozgo.com/Gestures.zip

Ngmoco has a game with a similar interface (Star Defense Prelude free download):
http://itunes.apple.com/us/app/star-defense-prelude/id328919422?mt=8

EDIT: Fixed broken link.

Take a look

that’s amazing! thanks for sharing!

Very cool of you to share this. This would make a great addition to the wiki. :smile:

Giving it a go tonight. Will let you know if I come across any issues.

Amazing work ! Too bad I’m not fluent in C, would it be too much to ask for JS version ?

Very cool. Really appreciate the share, virtual beers on me! Would also hail a JS version of this nifty coding.

Best,
B.

How very generous. Normally people only share gestures, not gesture code :wink:

Thanks, Rozgo.

My current project won’t be implementing anything nifty like this yet, but I like seeing what is possible. :slight_smile:

Thx for sharing! Don’t know C# at all and was wondering how easy would it be to modify this script to limit the amount you can drag left, right and up and down?

Hats off for sharing! JS person myself, but very nice to have for reference.

greetings rozgo,

thanks for sharing! the script works perfect, and i dig into trying to understand it.

at a certain point, i was confused why the camera is not located at the origin, because you are resetting its position here:

transform.position = Vector3.zero;

but then i understood, by:

transform.localRotation *= Quaternion.Euler(orbitSpeed.y, orbitSpeed.x, twistSpeed);
transform.position = -transform.forward * zoomDistance;

you are changing its rotation, and then - as the rotation is not zero, by moving it “backword” along its localrotation, its moved away from the center.

what i´m trying to achieve is to limit the area of “orbiting” (the cam is looking on a plane in my case, but user should not be able to look at the plane from “below”.

do you have any tipp how to limit the area the user can orbit?
any help would be very much appreciated - i searched the forum but didnt find sth really suitable…

would be great if you could push me in the right direction :wink:

thanks,
thomas

EDIT: the mouse-orbit script gave me the answer, should have looked there earlier :wink:
sorry - it wasn´t that difficult to find

greetings, thomas

The link is no longer valid, could someone post this please?

Thanks!

Ftp service is down, I sent the host company a msg to verify. Send me an email where I can send you the code.

EDIT: Fixed the link in the first post.

I’d like to add a target transform to the Gesture.cs code vs how it is now by targeting world 0,0,0. Any thoughts on how this could be implemented?

Thanks,
CapnJ

wish i could try this out right now… sitting in a HORRIBLE class and no Unity on this laptop :frowning:

Hey CapnJ , i tried this:

declared this on top:

public Transform target;

them at the end of the update i added the target.position at the transform position, like this:

// apply zoom
/transform.position += transform.forward * zoomSpeed * Time.deltaTime;
zoomDistance = transform.position.magnitude;
/

zoomDistance = 10;

// apply orbit and twist
transform.position = Vector3.zero;
transform.localRotation *= Quaternion.Euler(orbitSpeed.y, orbitSpeed.x, twistSpeed);
transform.position = (-transform.forward * zoomDistance) + target.position;

it works fine with the camera position, but the zoom starts bumping like crazy! that’s why i commented the apply zoom code, and set to 10 :confused:

:confused: i’ll try to fix this… no idea how though XD