Hi,
I’d like to rotate my GameObject with a set of spheres as children around itself. Until now I’ve written the following code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ObjectRotator : MonoBehaviour{
Vector3 mPrevPos = Vector3.zero;
Vector3 mPosDelta = Vector3.zero;
void Update(){
if(Input.GetMouseButton(0)){
mPosDelta = Input.mousePosition - mPrevPos;
if(Vector3.Dot(transform.up, Vector3.up)>=0){
transform.Rotate(transform.up, -Vector3.Dot(mPosDelta, Camera.main.transform.right), Space.Self);
}
else{
transform.Rotate(transform.up, Vector3.Dot(mPosDelta, Camera.main.transform.right), Space.Self);
}
transform.Rotate(Camera.main.transform.right, Vector3.Dot(mPosDelta, Camera.main.transform.up), Space.Self);
}
mPrevPos = Input.mousePosition;
}
}
But this code does not work as I want to. I’d like that my GameObject stays in the same position, but on mouse drag it rotates. Could you help me please?