Getting starting rotation and adding it to Mathf.PingPong

Sorry to be asking another question in such a short space of time, but this one has me stumped. I’m trying to make a simple object rotate back and forth. For ease of use (as this script will probably be applied to many objects) I’m trying to get the starting rotation and use it as a basis for rotation via Mathf.PingPong. (It’s intended to be a camera, panning back and forth.)

However, whenever I try to get the starting rotation, it always gives very small values like 0.8 even if the actual rotation value is, say, 40 or 50 degrees in that axis. A few sample measurements it gives are 0.9659258, -0.2588191 and -4.216698e-08, where the actual starting rotation was 90, 0 and 30 respectively. The Mathf.PingPong function works otherwise fine, it’s just these starting angles that aren’t working.

Here’s the code I’m using:

using UnityEngine;
using System.Collections;

public class CameraMovement : MonoBehaviour
{
	public float rotateSpeed = 0.1F;
	public float rotateAmount = 90.0F;
	public Quaternion startRotation;
	
	void Awake()
	{
		startRotation = transform.rotation;
	}
	
	void FixedUpdate()
	{
			transform.rotation = Quaternion.Euler(startRotation.z, Mathf.PingPong(Time.time * rotateSpeed, rotateAmount)+(rotateAmount/2)+(startRotation.y), startRotation.x);
	}
}

Transform.rotation is a Quaternion, not euler angles. Quaternions are 4D, non-intuitive constructs where the x,y,z, and w values range from 0.0 to 1.0.

If you want to deal with angles, you can use Transform.eulerAngles, but there are some gotchas associated with using them. You might consider using Mathf.Sin() rather than Mathf.PingPong().