1
\$\begingroup\$

I am new in unity and I am developing a game where I want to rotate my object I try this code for it.

if(Input.GetMouseButton(0)){
        if(Input.GetMouseButtonDown(0)){
            LastMousePosition = Input.mousePosition;
        }
        else if(LastMousePosition.y> 112){
            Bow.Rotate(Vector3.up*(Input.mousePosition.y - LastMousePosition.y));
        }
        else if(LastMousePosition.y<112){
            Bow.Rotate(Vector3.down*(Input.mousePosition.y - LastMousePosition.y));
        }
        LastMousePosition = Input.mousePosition;
    }

It works fine for me but my object is rotate from It's center point and I want to rotate it from another point can any one help me with this?

\$\endgroup\$
  • 1
    \$\begingroup\$ translate your local matrix to the "otherpoint" \$\endgroup\$ – Tordin Sep 15 '14 at 11:24
  • \$\begingroup\$ How to do that? Any sample code will help me a lot. \$\endgroup\$ – Dharmesh Kheni Sep 15 '14 at 11:29
  • \$\begingroup\$ Saying you're new to Unity and advertising a Unity consulting company is a strange combination. Please don't advertise on this site, thanks. \$\endgroup\$ – MichaelHouse Sep 15 '14 at 14:51
4
\$\begingroup\$

Create an empty gameobject, make it child of your gameobject. Move it to one of the corners you want to rotate about, Use RotateAround to rotate your gameobject. You could also do the same through code by calculating the dimensions of your gameobject.

Edit: You could use these scripts to make your life easier: PivotManager, SetPivot.

\$\endgroup\$
  • \$\begingroup\$ Thanks for help it works for me. Dharmesh \$\endgroup\$ – Dharmesh Kheni Sep 16 '14 at 11:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.