Download

Preventing UFO rotation in flying demo

The flying demo project controls vehicle rotation by just adding the appropriate (AxisInput * deltaseconds) to a FRotators pitch, yaw, and roll, then it adds that to the vehicle’s local rotation. It feels pretty decent in 90% of cases, but it has the annoying effect of automatically rolling the vehicle level if you take your hands off the controls. I tried to fix this by adding a check after the rotator has been computed, and not applying any rotation if there is no input on any axis:


	// Calculate change in rotation this frame
	FRotator DeltaRotation(0,0,0);
	DeltaRotation.Pitch = CurrentPitchSpeed * DeltaSeconds;
	DeltaRotation.Yaw = CurrentYawSpeed * DeltaSeconds;
	DeltaRotation.Roll = CurrentRollSpeed * DeltaSeconds;

	// Rotate plane
	FRotator nullRot(0, 0, 0);
	if (DeltaRotation != nullRot) //If DeltaRotation is non-null...
		AddActorLocalRotation(DeltaRotation); //Rotate the vehicle

As far as I can tell, this has no perceivable effect; the vehicle still levels itself out whenever you take your hands off the controls. Is there an obvious reason this isn’t working as expected?