So I am making this game where the character is stationary and it can rotate around 360 degrees in any direction and I’m making this game for the android platform.
I have made a script by watching some videos and going through the forums. it is working but not quite right.
This is my script
using UnityEngine;
public class Main : MonoBehaviour
{
private Touch initTouch = new Touch();
public float speed = 0.02f;
private float rotX = 0f;
private float rotY = 0f;
public float direction = -1;
void Start()
{
rotX = transform.rotation.x;
rotY = transform.rotation.y;
}
void Update()
{
foreach (Touch touch in Input.touches)
{
if (touch.phase == TouchPhase.Began)
{
initTouch = touch;
}
else if (touch.phase == TouchPhase.Moved)
{
float deltaX = initTouch.position.x - touch.position.x;
float deltaY = initTouch.position.y - touch.position.y;
rotX -= deltaY * Time.deltaTime * speed * direction;
rotY += deltaX * Time.deltaTime * speed * direction;
transform.rotation = Quaternion.Euler(rotX, rotY, 0f);
}
else if (touch.phase == TouchPhase.Ended)
{
initTouch = new Touch();
}
}
}
what this should do is when I drag my finger along the screen the player should turn in the direction of my finger but when I drag the finger along a direction and drag it back without lifting the finger the object still keeps rotating in the same direction
Idk if this is caused by my mobile device or if something is wrong with the code
I have some experience in unity but I don’t have that much knowledge in coding
Pls let me know if I can change anything to fix this or use another way to do this