- Home /
Question by
Bentoon · Jan 03, 2015 at 03:59 AM ·
camera-movementaxistouchscreen
moving camera in increments, with Touch
Hello All,
I am controlling a camera with arrow Keys (up, down left, right) in jumps of 10 units, each time you press.
I am making this for touchscreen and also want the touch input to snap to stages along both the X & Y axis.
Almost like the Camera was on a lattice and could only move in steps on the X,Y ... Like when you move checkers
The Arrow keys work, but the touch does all over the board.
Thanks, Here's the javascript:
#pragma strict
// Moves object according to finger movement on the screen
var speed : float = 0.05;
var nonSpeed : float = 0;
function Update () {
if (Input.GetKey(KeyCode.RightArrow) ){
Debug.Log("right");
transform.Translate (Vector3(10,0,0) * Time.deltaTime*speed);
}
if ( Input.GetKey(KeyCode.LeftArrow) ){
Debug.Log("left");
transform.Translate (Vector3(-10,0,0) * Time.deltaTime*speed);
}
if ( Input.GetKey(KeyCode.UpArrow) ){
Debug.Log("Up");
transform.Translate (Vector3(0,-10,0) * Time.deltaTime*speed);
}
if ( Input.GetKey(KeyCode.DownArrow) ){
Debug.Log("Down");
transform.Translate (Vector3(0,10,0) * Time.deltaTime*speed);
}
if (Input.touchCount > 0 &&
Input.GetTouch(0).phase == TouchPhase.Moved) {
// Get movement of the finger since last frame
var touchDeltaPosition:Vector3 = Input.GetTouch(0).deltaPosition;
// Move object across XY plane
transform.Translate (-touchDeltaPosition.x * speed,
0,0);
transform.Translate (0,-touchDeltaPosition.y * nonSpeed,0);
}
}
Comment
Your answer
Follow this Question
Related Questions
Android touches called the Input.GetAxis('Mouse X') 0 Answers
3d car left and right touch input 2 Answers
Cross platform camera controlls 0 Answers
tween Path animation & touch control 1 Answer