Fixing Rotation on Raised Pins

Maybe it can help some people facing the same issue…

On my project, I had an issue when raising the standing pins if they were not yet absolutely still, as this way they would keep on their rotation in the air and fall when lowered down for being already inclined.

The way I fixed this in my project started with the physics.
Set my gravity to -98 (not -981), then I changed the mass from all the pins to 153 (instead of 1.53 - let’s remember they were skinny giants), and changed the mass of the ball to 730. This combination made the behaviour of all objects to seem more natural, as their collisions and pin reactions. And also made the pins more steady before being raised.
But this was not solving the problem completely.

Finished fixing my project by researching and trying out some different codes until it finally worked.
Needed a way to make them straight before being raised, and this can be accomplished this way:
transform.rotation = Quaternion.Euler(0, 0, 0);

Then I needed them to not rotate at all anymore, which can be set by this line:
rigidBody.freezeRotation = true;

So the whole RaisedIfStanding function, on Pin.cs, ended up looking like this:

public void RaiseIfStanding () {
    if (isStanding ()) {
        rigidBody.useGravity = false;
        transform.rotation = Quaternion.Euler(0, 0, 0);
        rigidBody.freezeRotation = true;
        transform.Translate(new Vector3(0, distToRaise, 0), Space.World);
    }
} 

So far it’s been working great! :slight_smile:

You can try “rigidBody.isKinematic = true;” instead of “useGravity = false;” + “freezeRotation = true;”. For me works fine and it’s only one line of code.

If you also need to reset rotation try “transform.rotation = Quaternion.identity;”. In Unity3d this quaternion corresponds to “no rotation”. :slight_smile:

Privacy & Terms