Question by
luci_crossfire · Jul 05, 2019 at 06:05 AM ·
androidrotation
How do I rotate a sphere while swiping, in the direction that I am swiping ?
So, as the title says I want that if I rotate left,right,up,down or in diagonal my object moves in that specific direction. The problem is that I want to make it logical for the user, picture this: The camera is looking at this sphere object. The user swipes left, in that case the object should always move towards left (regardless of its orientation).
I had some results with this:
void Update()
{
if (Input.touchCount == 1)
{
// GET TOUCH 0
Touch touch0 = Input.GetTouch(0);
// APPLY ROTATION
if (touch0.phase == TouchPhase.Moved)
{
transform.Rotate(0f, -touch0.deltaPosition.x*Time.deltaTime*5*AdjustForVertical(), 0f);
transform.Rotate(-touch0.deltaPosition.y*Time.deltaTime*5*AdjustForHorizontal(), 0f, 0f);
}
}
}
float AdjustForVertical() {
if (Vector3.Dot(transform.up, Vector3.down) > 0)
{
return -1;
}
else
{
return 1;
}
}
float AdjustForHorizontal() {
if (Vector3.Dot(transform.right, Vector3.left) > 0)
{
return -1;
}
else
{
return 1;
}
}
The problem is that once orientation changes the object moves in another direction which only makes it confusing for a player.. May game is going to be on android so I use touches. I would prefer if you could show me hints with touches as well.
Thank you so much and let me know if you have any idea how to achieve this.
Comment