- Home /
Question by
hanzallahmaseed · Jan 05, 2020 at 07:33 AM ·
rotationunity 2dtouchjoystick
Rotate a 2D object slowly to the touch position
Hi! I am creating a circular Joystick like setup in Unity. Played a lot with it in different ways but I don't get the desired results.
void Update()
{
//movement = Input.GetAxisRaw("Horizontal");
if (Input.touchCount > 0)
{
touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Began)
{
firstTouchY = touch.position.y;
}
if (touch.phase == TouchPhase.Moved)
{
if (touch.deltaPosition.y < 0)
{
movement = -1;
}
else if (touch.deltaPosition.y > 0)
{
movement = 1;
}
rotatePlayer();
}
}
}
private void rotatePlayer()
{
transform.RotateAround(Vector3.zero, Vector3.forward, movement * Time.fixedDeltaTime * moveSpeed);
}
This is what I want. Help will be appreciated greatly. Thanks!
capture.jpg
(117.9 kB)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612221046im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Rotate An Object Toward The Direction The Joystick Is Pressed, can you help me? I am stuck 1 Answer
Rotate object after swipe according to swipe direction 0 Answers
Hi, knife hit, how do you control the speed of the wheel and the speed of the knife? 1 Answer
Make an obect take priority over another when touched? 0 Answers
Need Help, Rotating a wheel with touch or using the mouse 2 Answers