- Home /
Question by
Bentoon · Mar 05, 2015 at 05:56 AM ·
c#cameratouchscreenrotatearound
rotate camera around object with Touch
Hello I am using the Unity "Rotate" script (below) works great on computer but on a touchscreen instead of a picking up where it left off (so I can go continuously around an object) It resets the rotation so I only ever rotate the same part of if Thanks for your help, Here is the script:
using UnityEngine;
using System.Collections;
public class rotateCam1 : MonoBehaviour {
public Transform target;
public float xSpeed = 125.0f;
public float ySpeed = 50f;
public float resetTime = 1.0f; //How long to take to reset
private Vector3 startDirection = Vector3.zero; //How far away to orbit
private float x = 0.0f;
private float y = 0.0f;
private float z = 0.0f;
private Quaternion startRotation;
private Quaternion rotation;
private bool resetting = false;
private float resetTimer = 0.0f;
void LateUpdate()
{
if (Input.GetMouseButtonDown(0))
{ startDirection = (transform.position - target.position);
startRotation = transform.rotation;
x = 0.0f;
y = 0.0f;
z = 0.0f;
}
if (Input.GetMouseButton(0))
{
x += Input.GetAxis("Mouse X") * xSpeed * 0.02f;
y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f;
z = 0.0f;
Reorient();
}
}
void Reorient()
{
rotation = Quaternion.Euler(y, x, z);
transform.rotation = rotation * startRotation;
transform.position = rotation * startDirection + target.position;
}
}
Comment
Your answer
Follow this Question
Related Questions
Rotatearaound a moving object 1 Answer
Orbit 2D camera around circle but keep lookat towards z axis 1 Answer
Multiple Cars not working 1 Answer
Camera.main.WorldToScreenPoint(touch.position). Help !!! 1 Answer
Distribute terrain in zones 3 Answers