Freeze Rotation - Not remaining ticked

Hi,
I have selected the Freeze Rotation for X & Y and also tried X,Y & Z but when playing the game the ship is still able to rotate in different angles.
Noticed when i do click play the ticks disappear and i am unable to apply them during run-time.

Ive gone over the video again to check not missed anything but cant see what I’m doing wrong.

Anyone got any ideas ?

Below video showing what happens with the rocket rotating on the floor.

Cheers in advance :slight_smile:

2 Likes

The video isn’t working for me (in Opera, fwiw). I was having issues with my player object rotating in the X and Y until I captured and forced the constraints. The first thing I’d check is that both the object in-scene, as well as the prefab do have the Z-position, and XY-rotation constraints selected. If it’s still broken, you might want to try what I did with the constraints:

class member variable:
private RigidbodyConstraints rigidbodyConstraints;
inside Start():
rigidbodyConstraints = myRigidbody.constraints;
Inside your Thrust/Rotation method:
        myRigidbody.freezeRotation = true;
        transform.Rotate((-v) * Vector3.forward * rotationForce);
        myRigidbody.freezeRotation = false; // possibly cancelling the constraints?
        myRigidbody.constraints = rigidbodyConstraints; // likely, as this seems to be a fix.
4 Likes

Excellent, worked :+1:

Cheers JackDraak, I will do some reading up to see exactly what this is doing but I assume this is forcing the FreezeRotation via code rather than the inspector ?

I added the below and it worked a treat :

Class member variable:
RigidbodyConstraints rigidbodyContraints;

Start()
rigidbodyConstraints = myRigidbody.constraints;

Rotation method:
rigidBody.constraints = rigidbodyConstraints;

2 Likes

I had to go back and check… when I commented out my line:

myRigidbody.constraints = rigidbodyConstraints;

and watched my player object in the inspector, it wasn’t long before the XY-rotation constraints were un-checked. This is a bug we should mention to @ben

When we use Ben’s code:

myRigidbody.freezeRotation = false

We’re also inadvertently clearing the rotation-constraints from the object. Therefore, we can force them back with the RigidbodyConstraints we stored in Start().

4 Likes

Today, i discovered the same problem. Thank you for help and work around!

Just to let you know we fix this code later in the section.

4 Likes

Privacy & Terms