- Home /
Drag & Rotate an object around another object at a certain distance
Hi guys, I am fairly new to Unity and after fighting with this issue now for two days I decided to give up and ask here for an answer.
So my issue is this: (the game is a top-down puzzle game). I have a sphere that is flat in the middle, and a cube that is attached to the border of the sphere. What I want is that I can drag the cube around the sphere. I hope the picture explains more what I am after. I've been trying to figure this out with this:
void OnMouseDrag()
{
if(Input.GetAxis("Mouse X") > 0)
{
transform.RotateAround(pivot,Vector3.up, speed*Time.deltaTime);
}
if(Input.GetAxis("Mouse X") < 0)
{
transform.RotateAround(pivot,Vector3.up, -speed*Time.deltaTime);
}
But this does not really work as I want it. It follows the mouse position and not the actual cube.
I've also tried fiddling around with RigidBody and dragging rigid bodies and applying different hinges but I can't get them to work at all.
Your answer
Follow this Question
Related Questions
adding drag to a relative force 0 Answers
Character Slowly sliding off platform 1 Answer
A position locked hinge joint with drag and no gravity? 1 Answer
Rigidbody loses speed 1 Answer
Objects with colliders going through walls and each other. 3 Answers