Transform with screen tap controls
Does anyone have a script or know of a tutorial anywhere for creating a lens with movement controls that allow the user to use screen tap to move or rotate an object a little bit at a time?
Similar to the lens Apoc has with a remote control car.
I would like to use the controls to move the camera in the scene instead.
Hi JAK,
I've made an example project for you based on the Portal template. It uses some UI buttons to move the camera forward, backward, and rotate 90 degrees left and right.
Link to project file
The basic setup is:
Each button calls a behavior script custom trigger when pressed. Each button has a corresponding object (under Camera Behaviors) with a movement tween.
The two rotational objects each have Behavior scripts on them that run their tweens when their matching custom trigger is called.
The forward / back movements are a bit more tricky, since the tween doesn't let you move relative to the object rotation (just world or parent). So I made a simple helper script called RunObjectRelativeTween that listens for a custom triggers and runs a position tween in object space when called. This might be a little confusing, but you just have to set the "offset" parameter on that script to the relative movement you want the tween to do.
Let me know if you need any more help!
Jacob
Awesome! Thanks Jacob.
Is there a way to prevent the portal from allowing the user to leave the portal space when using the movement buttons?
You can use a script like this to limit the object position.
Just put this script on a new object, then set Object to your Camera. Create two empty objects to represent the corners of your portal area, and set these as Corner A and Corner B. Position these in the opposite corners of the space you want the camera to be constrained in. Also note that this does include Y (height off the ground), so one of your corners should be high off the ground.
As an example, in the project I uploaded earlier I can set the corner positions to: (-308, 0, -268) and (518, 265, -974). The camera is forced to stay between these points for each axis (x, y, z).
Let me know if you have any questions about this!
Jacob