PlayMaker Help & Tips > PlayMaker Help

iOS Touch to Orbit Camera

(1/2) > >>

marcos:
Hey,

Just wondering how I would go about making a system that does the following two things:
Firstly, orbits the camera around an object based on touch input, both vertically and horizontally. Touching the screen and sliding horizontally orbits the camera horizontally, and vertically orbits vertically. Just a touch based mouse orbit sort of setup.
Secondly, when the touch is released, smoothly move back to the original camera position.

Many thanks in advance.

marcos:
I suppose controlling rotation of an object via touches would work also, however this also has me a bit stumped. Yet to get my head around how to do this.

Alex Chouls:
Make sure you grab the bug fix for Get Touch Info here: http://hutonggames.com/playmakerforum/index.php?topic=387.0

You can use this action to get DeltaX and DeltaY for a touch and rotate the camera by those deltas.

When making an orbit camera it can help to parent the camera to a node that acts as the pivot (e.g, centered on the object), then rotate the pivot instead of the camera.

To rotate and then return to the starting position, change states using the Touch Event action. E.g., start in an Idle state, on touch began go to a Rotate state, and on touch finished go to a Reset state and then back to Idle.

You can also separate input and camera motion into 2 FSMs that talk to each other with Send Event and Set Event Data actions:

Input FSM: Idle <-> DragTouch
Camera FSM: Idle -> Orbit -> Reset -> Idle

This is generally more flexible with less duplication of actions.

Hope this helps some!

marcos:
Thanks for the detailed response Alex, going to give this a go tonight!

Is pinch to zoom in and out doable with Playmaker at the moment? That would really put the icing on the cake!

Many thanks once again!

marcos:
Got this working nicely, thanks again Alex!

I found that the orbiting was a bit odd at first, so I constrained the Z rotation entirely with the script that ships with Unity, and limited the X rotation from -50 to 50. This prevented a strange sudden rotation on the y axis when orbiting to +/- 90 degrees on the x axis.

The rotation is really predictable and nice feeling now, I just need to change the direction the camera orbits when swiping up and down. I think this should be achievable by multiplying it by -1.

Navigation

[0] Message Index

[#] Next page

Go to full version