Rigidboday fixed rotation not working.

I’ve got a player GameObject thats a Rigidbody. This has been setup to Freeze Rotation on X and Z.

If I start bumping into walls the Rigidbody still rotates…

I event tried to force the issue in script:

void FixedUpdate () {
	if (!isServer) {
		return;
	}

	Quaternion startRotation = _rigidbody.rotation;

	if (_moveForward) {
		float moveAmount = speed * Time.deltaTime;
		_rigidbody.MovePosition(_rigidbody.position + _rigidbody.transform.forward * moveAmount);
	}

	if (_moveBackward) {
		float moveAmount = (-speed * 0.6f) * Time.deltaTime;
		_rigidbody.MovePosition(_rigidbody.position + _rigidbody.transform.forward * moveAmount);
	}

	if (_turnLeft) {
		Quaternion rotateAmount = Quaternion.Euler(new Vector3(0f, -angularSpeed, 0f) * Time.deltaTime);
		_rigidbody.MoveRotation(_rigidbody.rotation * rotateAmount);
	}

	if (_turnRight) {
		Quaternion rotateAmount = Quaternion.Euler(new Vector3(0f, angularSpeed, 0f) * Time.deltaTime);
		_rigidbody.MoveRotation(_rigidbody.rotation * rotateAmount);
	}

	if (_jump && _isGrounded) {
		_isJumping = true;
	}

	if (_isJumping && jumpTimeLeft > 0) {
		float moveAmount = jumpSpeed * Time.deltaTime;
		_rigidbody.MovePosition(_rigidbody.position + _rigidbody.transform.up * moveAmount);

		jumpTimeLeft -= Time.deltaTime;
	} else if (_isJumping) {
		_isJumping = false;
		jumpTimeLeft = jumpTime;

	}

	if (_shoot) {
		_isShooting = true;
	}

	if (_isShooting && shootTimeLeft == shootTime) {
		GameObject go = ObjectPool.instance.GetObject ("Normal Bullet");
		go.GetComponent<NormalBullet> ().owner = _rigidbody.gameObject;
		shootTimeLeft -= Time.deltaTime;
	} else if (_isShooting && shootTimeLeft > 0) {
		shootTimeLeft -= Time.deltaTime;
	} else if (_isShooting && shootTimeLeft <= 0) {
		_isShooting = false;
		shootTimeLeft = shootTime;
	}

	byte bits = (byte)_rigidbody.constraints;
	Quaternion frozenRotation= new Quaternion(
		(bits & (1 << 4)) != 0 ? startRotation.x : _rigidbody.rotation.x,
		(bits & (1 << 5)) != 0 ? startRotation.y : _rigidbody.rotation.y,
		(bits & (1 << 6)) != 0 ? startRotation.z : _rigidbody.rotation.z,
		_rigidbody.rotation.w
	);
	_rigidbody.rotation = frozenRotation;
}

How to I freeze the rotation of a GameObject with a Rigidbody on it?

Well, When you control a rigid body movement with transform, freezing rotation wouldn’t help because it simply overwrites physics engine values. Use _rigidbody.velocity instead of _rigidbody.MovePosition and use _rigidbody.angularVelocity instead of _rigidbody.MoveRotation. This will work because it allows the physics engine to controll the constrains you have given to rigidbody.

Hope it helps. :slight_smile: