playMaker

Author Topic: iOS Touch to Orbit Camera  (Read 6439 times)

marcos

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 199
iOS Touch to Orbit Camera
« on: June 29, 2011, 03:22:15 AM »
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

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 199
Re: iOS Touch to Orbit Camera
« Reply #1 on: July 01, 2011, 02:50:53 AM »
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

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: iOS Touch to Orbit Camera
« Reply #2 on: July 01, 2011, 03:06:06 AM »
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

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 199
Re: iOS Touch to Orbit Camera
« Reply #3 on: July 01, 2011, 03:38:10 AM »
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

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 199
Re: iOS Touch to Orbit Camera
« Reply #4 on: July 01, 2011, 11:27:55 AM »
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.

marcos

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 199
Re: iOS Touch to Orbit Camera
« Reply #5 on: July 09, 2011, 06:20:03 AM »
In trying to advance the camera FSMs I've come across a problem!
Basically I want to get the camera to return to the original orientation when I release a touch, which is easy to do when I return to a set Vector. The problem arises when I try to get the camera to rotate back around behind the character again (resetting the Y axis), but maintain the same height that the player has rotated to (maintaining the X axis).

If I rotate to a value beneath the character, this works as intended. However if I rotate to a point above the character, upon releasing the touch the camera rotates to the same distance, only beneath the character rather than above. Upon closer inspection, I found that the object's rotation wasn't being reflected between 0-360 on the object itself, rather a 0 to 90 twice and 0 to -90 twice.

Basically no idea how to tackle this, there is a good chance there is a super simple solution to this problem but I'll throw it out to you guys in the mean time.

Thanks in advance.