- Home /
how to stop rotation from being uncontrollable
So I wrote some code to make an object rotate if I swiped left or right using System.Collections; using System.Collections.Generic; using UnityEngine; public class Rotater : MonoBehaviour { public Transform player; void Update() { if (Input.touchCount == 1) { // GET TOUCH 0 Touch touch0 = Input.GetTouch(0); // APPLY ROTATION if (touch0.phase == TouchPhase.Moved) { player.transform.Rotate(0f, 0f, touch0.deltaPosition.x); } } } }
and the problem is when I swipe fast the rotation will be uncontrollable. So I want the input to be less sensitive.
my goal is for the rotation to be like rolly vortex
my setup: (watch for context: https://youtu.be/eL0JK5x6Tz0)
I made an empty object and put it in the center
made the empty object a parent of my player
and finally, I put my code in the empty object
this setup made the player rotate in sort of an orbit which like I told you is similar to rolly vortex.
Answer by vardevelopment · Jun 22, 2018 at 10:41 PM
I never used touch input so I'm assuming you just want to decrease that value of your input between frames. if I am correct I suppose you would just divide your input value until it is suitable.
player.transform.Rotate(0f, 0f, touch0.deltaPosition.x / 5.0f);
I'm not sure if that is what you meant, but if it is, just change the 5.0f around if need be until it is the correct coefficient.
Your answer
Follow this Question
Related Questions
Making a bubble level (not a game but work tool) 1 Answer
Flip over an object (smooth transition) 3 Answers
How can I get my character to move forward in the direction of the camera? 2 Answers
Problems after rotating character. 0 Answers
In unity 2D c# how to rotate an object like geometry dash? 1 Answer