- Home /
Question by
skoandi · Feb 03, 2013 at 05:30 PM ·
androidiostouchsmoothdamp
SmoothDamp touch look iOS Android
Can someone help me to smooth the touchlook movement? Thanks! (I've tried for 5h!!!)
#pragma strict
var sensitivityX : float = 5.0;
var sensitivityY : float = 5.0;
var invertX : boolean = false;
var invertY : boolean = false;
function Update () {
var rect = Rect(427,0,427,480);
if(Input.touches.Length > 0){
for (var touch : Touch in Input.touches) {
if(touch.phase == TouchPhase.Moved && rect.Contains(touch.position)){
var delta : Vector2 = touch.deltaPosition; //Input.touches[0].deltaPosition;
var rotationZ = delta.x * sensitivityX * Time.deltaTime;
rotationZ = invertX ? rotationZ : rotationZ * -1;
var rotationX : float = delta.y * sensitivityY * Time.deltaTime;
rotationX = invertY ? rotationX : rotationX * -1;
transform.localEulerAngles += new Vector3(rotationX, rotationZ, 0);
}
}
}
}
Comment
Answer by EHogger · Feb 04, 2013 at 03:24 AM
On your last line when you apply the rotation, you probably want to use Vector3.Lerp or similar.
http://docs.unity3d.com/Documentation/ScriptReference/Vector3.Lerp.html
Edit - infact you mentioned smoothdamp in the title, although I don't see it in your script.
Your answer
Follow this Question
Related Questions
Make an object move in the direction of touch 0 Answers
Having an issue with getting my touch controls working 0 Answers
Touch joystick tutorials ? 0 Answers
android touch input 1 Answer
Replace Input.GetAxis with Touch 2 Answers