Cant add Torque and Rotation to a rigidbody in the same frame?

Hi guys, could really do with some expert help here as I’m tearing my hair out with this! I cant find any other help articles which address this problem, so hopefully I’m overlooking something very simple.

Basically, I’m writing a top-down helicopter TPS (think Desert Strike). So far its going really well and I have a great model which flies around using proper physics and feels very real.

In each FixedUpdate I’m getting the 3 input axes (pitch, yaw, roll (the axes around x y z respectively)) and then calling my moveplayer method. This applies forces along x and z (y is constrained in the rigidbody settings) and applies a torque around y. So far it works beautifully.

Here’s where the problem starts: I want to tilt the helicopter in the direction of travel, but when I apply any sort of rotation command to x or z to pitch or roll (x or z) it works but the torque command stops working so the player can’t rotate left or right. Where am I going wrong?

Here’s the gist of my code:

	void FixedUpdate ()
	{
			// Get pitch input (-1 to 1)
			float pitch = Input.GetAxis ("Vertical");

			// Get yaw (turn) input (-1 to 1)
			float yaw = Input.GetAxis ("Horizontal");

			// Get roll input (-1 to 1) - Keys Q & A
			float roll = Input.GetAxis ("Roll");

			// Move player
			MovePlayer (pitch, yaw, roll); 
	}


	void MovePlayer (float pitch, float yaw, float roll)
	{
		// move helicopter in pitch direction
		playerRigidbody.AddForce (transform.forward * pitch * thrust);	

		// turn helicopter in yaw direction
		playerRigidbody.AddTorque(transform.up * yaw * 100);

		// move helicopter in roll direction
		playerRigidbody.AddForce (transform.right * roll * thrust);

		//Clamp helicopter speed
		playerRigidbody.velocity = Vector3.ClampMagnitude (playerRigidbody.velocity, maxSpeed);

		// tilt helicopter in pitch direction - enabling this line stops rotation working!
		transform.Rotate (transform.right, pitch*20);
}

I would be VERY grateful if anyone can help me. I’ve certainly had a lot of help from reading existing answers so far.

Cheers,
Dave

add all forces and torques together and apply them only once. they get overridden this way.

OK, I’ve sussed it myself! Here’s the solution for anyone interested. (There’s certainly nothing out there about this).

	// tilt helicopter 
	pitchRot = pitchInput * 10f; // pitchInput is vertical input axis
	rollRot = rollInput * 10f;  // rollInput is horizontal input axis
	transform.localEulerAngles = new Vector3(Mathf.Clamp (pitchRot, -20, 20), transform.localEulerAngles.y, Mathf.Clamp (-rollRot, -20, 20));

This allows addtorque to be applied around the Y axis.