Reputation: 3134
I wanted to rotate the hand 360 degrees perfectly or in it's y axis only. The y-axis is the circle. Right now it rotates at 300 degrees perfectly.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerControl : MonoBehaviour
{
public Transform pullStickTransform;
public Vector3 centerPt;
private Vector3 currentPosition;
private Vector3 diffPosition;
private Vector3 currentRotation;
public float dragSpeed;
void Update()
{
if (Input.touchCount > 0)
{
Touch currentTouch = Input.GetTouch(0);
Vector3 touchPos = currentTouch.position;
touchPos.z = Camera.main.WorldToScreenPoint(transform.position).z;
if (currentTouch.phase == TouchPhase.Moved)
{
float rotX = touchPos.x * .01f * Mathf.Deg2Rad;
pullStickTransform.RotateAround(Vector3.up, -rotX);
}
}
}
}
Upvotes: 2
Views: 168
Reputation: 2102
You're doing all this mangling of your rotation:
* .01f * Mathf.Deg2Rad
The RotateAround method takes input in degrees, but you're using Deg2Rad here right before it, which says to me your just applying random numbers to scale to approximately what you need. The easy fix here is to just apply one more conversion: if it goes to 300 and you want it to go to 360 you could chain in another scaling term:
* .01f * Mathf.Deg2Rad * (360.0f/300.0f);
The better way would (IMO) to be methodical about it. Find the min/max values of your touch input, get the range, then get the range of values you'd like to apply to your image, and use the ratio to scale your input.
Upvotes: 0