- Home /
Question by
zico_mahilary · Sep 24, 2013 at 05:25 AM ·
rotatedelta position
iOS - Jerky transform.Translate and transform.Rotate
hi, im developing a prototype and i want to make a gameobject rotate clockwise or anticlockwise when the player swipes up or down the screen. So far it is working but the movement is not smooth and i need the rotation to continue for as long as the player is touching the screen after the swipe. Please help me out on this. Heres the code
function Update ()
{
for (var touch : Touch in Input.touches)
{
if(touch.deltaPosition.y >= 1 && touch.position.x>250)
transform.Rotate(Vector3(0,0,50) * Time.deltaTime);
if(touch.deltaPosition.y <= -1 && touch.position.x>250)
transform.Rotate(Vector3(0,0,-50) * Time.deltaTime);
}
}
Comment
Best Answer
Answer by zico_mahilary · Sep 24, 2013 at 05:41 AM
well i fixed it myself.... heres the code if anyone needs:
var a = 0;
var b = 0;
function Update ()
{
for (var touch : Touch in Input.touches)
{
if(touch.deltaPosition.y >= 1 && touch.position.x>250)
a = 1;
//transform.Rotate(Vector3(0,0,50) * Time.deltaTime);
if(touch.deltaPosition.y <= -1 && touch.position.x>250)
b = 1;
//transform.Rotate(Vector3(0,0,-50) * Time.deltaTime);
if(a==1)
{
transform.Rotate(Vector3(0,0,50) * Time.deltaTime);
}
if(touch.phase == TouchPhase.Ended)
a=0;
if(b==1)
{
transform.Rotate(Vector3(0,0,-50) * Time.deltaTime);
}
if(touch.phase == TouchPhase.Ended)
b=0;
}
}
Your answer
Follow this Question
Related Questions
Camera rotation around player while following. 6 Answers
How do I rotate object smoothly 3 Answers
How to have vertical and horizontal axis work at the same time 1 Answer
RotateAroundPivot rong offset 0 Answers
Help rotating an Object 1 Answer