2
votes

I want to move connected rigid bodies as in image example, one of them needs to rotate around a point. Then using ground check I want to rotate it back to line I tried using hinge joint 2d, using angle limits, but can not control rotating angle.

How can I achieve this effect? thanks.

rotate position]

Edit: Tagged both rigidbodies as fixed angle and then applied rotation to upper object

void Update () {

    if(Input.GetKeyDown(KeyCode.F)){

        zRotation += 45;

        myGameObject.transform.eulerAngles = new Vector3(myGameObject.transform.rotation.x, myGameObject.transform.rotation.y, zRotation);

    }
1

1 Answers

0
votes

How can I achieve this effect?

Point to the object then rotate it.

First you want to find the GameObject.

GameObject g = GameObject.Find("Object Name");

Save the original rotation so you can return to it.

Quaternion originalPos = g.transform.rotation;

Then rotate it to your liking.

g.transform.rotation = new Quaternion(x,y,z,w);

In addition you could use iTween to smoothen out the rotation.