- Home /
Drag rotation problem
Well.. i have a circle.. like casino roulette. All what i need is drag this circle and rotate it.
I used code snippets from other Questions.. but they dont work as i need.
I think it will work like :
OnMouseDown - get first finger/mouse position. OnMouseDrag - get current finger/mouse position and get Angle. After this, rotate object by this angle.
1 problem is when i try to rotate object for 360 degrees.. its Rewind rotate at some point..
Sorry my english.
Code i used from Mattias 1 solution.
using UnityEngine;
using System.Collections;
public class ObjectRotator : MonoBehaviour {
private float _sensitivity;
private Vector3 _mouseReference;
private Vector3 _mouseOffset;
private Vector3 _rotation;
private bool _isRotating;
void Start ()
{
_sensitivity = 0.4f;
_rotation = Vector3.zero;
}
void Update()
{
if(_isRotating)
{
// offset
_mouseOffset = (Input.mousePosition - _mouseReference);
// apply rotation
_rotation.y = -(_mouseOffset.x + _mouseOffset.y) * _sensitivity;
// rotate
transform.Rotate(_rotation);
// store mouse
_mouseReference = Input.mousePosition;
}
}
void OnMouseDown()
{
// rotating flag
_isRotating = true;
// store mouse
_mouseReference = Input.mousePosition;
}
void OnMouseUp()
{
// rotating flag
_isRotating = false;
}
}
And there is pic.
Your answer
![](https://koobas.hobune.stream/wayback/20220613063923im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to drag and throw 2D objects?(SOLVED) 5 Answers
The Drag RigidBody Script Is Not Working For Me 0 Answers
Dragging UI Image by touch 3 Answers
Move the screen when object close to screen borders. 0 Answers