1

I use this line to rotate object using mouse:

this._obj.transform.Rotate(new Vector3(0, -Input.GetAxis("Mouse X"), 0), Time.unscaledDeltaTime * this.speed); 

But I would like to smooth this out, with some delay like in Sketchfab when you use the mouse to rotate the object, just not sure how to do this properly. I'm not really familiar with the Quaternions that much.

Can someone give me some advice on how I just approach this?

1
  • You'll want to scale the magntidue by the Mouse X axis & keep the axis constant. Try this._obj.transform.Rotate(Vector3.down, Time.unscaledDeltaTime * this.speed * Input.GetAxis("Mouse X")); Commented Sep 25, 2019 at 21:29

1 Answer 1

2

Its a bit complicated just to rotate it. Here's a working version of what you want:

 public Vector3 hiddenRotation; void Start() { hiddenRotation = this.transform.rotation.eulerAngles; } void Update() { float sensitivity = 5.0f; //Get rotation vector Vector3 rot = new Vector3(0, -Input.GetAxis("Mouse X"), 0) * sensitivity; //Add rotation to hidden internal rotation hiddenRotation += rot; //Specify speed at which the cube rotates. float speed = 50.0f; float step = speed * Time.deltaTime; //Set new rotation (changing this function may allow for smoother motion, like lower step as it approaches the new rotation this.transform.rotation = Quaternion.RotateTowards(this.transform.rotation, Quaternion.Euler(hiddenRotation), step); } 

Which uses a hidden rotation and gets the transform.rotation to approach it.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.