- Home /
Transform rotating object with mouse to rotating object with touch !!!
Hi i have the MouseOrbit Script and i've edited it till it becomes the following, and what i want to remove This:
x += Input.GetAxis("Mouse X") * xSpeed * 0.02;
y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02;
and Replace it with touch one, so there is the Code:
var target : Transform;
var xSpeed = 250.0;
var ySpeed = 120.0;
var yMinLimit = -20;
var yMaxLimit = 80;
private var x = 0.0;
private var y = 0.0;
function Start () {
var angles = transform.eulerAngles;
x = angles.y;
y = angles.x;
// Make the rigid body not change rotation
if (rigidbody)
rigidbody.freezeRotation = true;
}
function LateUpdate () {
if (target) {
x += Input.GetAxis("Mouse X") * xSpeed * 0.02;
y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02;
y = ClampAngle(y, yMinLimit, yMaxLimit);
var rotation = Quaternion.Euler(y, x, 0);
transform.rotation = rotation;
}
}
static function ClampAngle (angle : float, min : float, max : float) {
if (angle < -360)
angle += 360;
if (angle > 360)
angle -= 360;
return Mathf.Clamp (angle, min, max);
}
but without removing any thing, just the GetAxis Thing
Answer by Graham-Dunnett · Mar 01, 2014 at 09:36 AM
Check out http://docs.unity3d.com/Documentation/ScriptReference/Input.GetTouch.html. The first example on this page shows how you can change the position of an object by using Touch. I'd imagine you can use the delta values from the example to change your x and y angle.
Check out http://docs.unity3d.com/Documentation/Manual/PlatformDependentCompilation.html for how to write code that runs on different platforms.
thanks but i want the script cuz i tried and didn't work
Your answer
Follow this Question
Related Questions
GetAxisRaw for touch device 0 Answers
EventSystem not detecting all UI elements 1 Answer
Android touches wrong after using the application at least once 0 Answers
Getting position of touch on gameObject 1 Answer
hold touch to move, tap to rotate 2 Answers