Hello I am trying to make a first person iPhone game. I need help making a script for my character move. I want the character
to follow my finger smoothly. If you can do this for me that would be great,if not that’s fine. Thank you for reading
using UnityEngine;
using System.Collections;
public class SwipeRotation : MonoBehaviour {
public float rotateSpeed = 10.0f;
private float pitch = 0.0f,
yaw = 0.0f;
private Touch currentTouch;
void Update ()
{
if (Input.touches.Length > 0)
{
for (int i = 0; i<Input.touchCount; i++)
{
currentTouch = Input.GetTouch(i);
if (Input.GetTouch(i).phase == TouchPhase.Moved)
{
pitch += currentTouch.deltaPosition.y * rotateSpeed * Time.deltaTime;
yaw += currentTouch.deltaPosition.x * rotateSpeed * Time.deltaTime;
this.transform.eulerAngles = new Vector3(-pitch, -yaw, 0.0f);
}
}
}
}
}
Sorry about the mess. Feel free to adjust values for the best result. Good luck.