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\$
3
  • 1
    \$\begingroup\$ translate your local matrix to the "otherpoint" \$\endgroup\$
    – Tordin
    Commented Sep 15, 2014 at 11:24
  • \$\begingroup\$ How to do that? Any sample code will help me a lot. \$\endgroup\$ Commented Sep 15, 2014 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\$
    – House
    Commented Sep 15, 2014 at 14:51

1 Answer 1

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\$
1
  • \$\begingroup\$ Thanks for help it works for me. Dharmesh \$\endgroup\$ Commented Sep 16, 2014 at 11:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .