- Home /
Question by
manu11795 · Oct 18, 2017 at 03:42 PM ·
camera-movementcamera rotatetouch controls
I need an help with my Touch camera please :(
I'm doing a touch controller for the rotation of my Maincamera around a ball. It works when i swipe, but the problem born when i throw my finger from the screen because the CamTransform.position reset every time by ball position. Anyway here is the code, hope let you understand better than i did.
void LateUpdate()
{
Vector3 dir = new Vector3(distanceX, distanceY, 0.0f);
rotation = Quaternion.Euler(0.0f, swipe * rotSpeed, 0.0f);
camTransform.position = player.position + rotation * dir;
camTransform.LookAt(player);
}
void FixedUpdate()
{
foreach (Touch touch in Input.touches)
{
if (touch.phase == TouchPhase.Began) //Touch Began
{
initTouch = touch;
touchPositionStart = touch.position.x;
}
else if (touch.phase == TouchPhase.Moved) //Touch Moved
{
touchPositionEnd = touch.position.x;
swipe = (touchPositionEnd - touchPositionStart);
Debug.Log(swipe);
}
else if (touch.phase == TouchPhase.Ended) //Touch Ended
{
initTouch = new Touch();
}
}
}
}
I think the problem is here.
Thank you :)
help.jpg
(24.4 kB)
Comment