Hello,

I have a security camera entity that sweeps across a 180 degree arc. When it finds a target, it tries to stay aimed at that target.

However, I'm having problems with angles being greater than 360 from each other, causing the camera to sometimes spin in the wrong direction, or outside of its 180 arc.

What I have at the moment is a kind of hacked together solution that works fine as long as the security camera is facing 'south' in WED. If I have one facing the opposite direction, it gets confused again.

Code:
		// IF ALERT IS RAISED
		if (alert == 1)
		{
			// Calculate direction to target
			vec_diff(tempVector,ball.x,my.x);
			vec_to_angle(alertAngle,tempVector);
			alertAngle.roll = 0;
			alertAngle.tilt = 0;
			// Crappy code to compensate for wildly different angles
			alertAngle.pan += 360;
			
			// Calculate difference between my angle, and direction to target
			tempAngle.pan = my.pan - alertAngle.pan;
			// Aim Spotlight towards target
			if (tempAngle.pan > 0)
			{
				// Rotate clockwise
				rotateDir = 1;
			}
			if (tempAngle.pan <= 0)
			{
				// Rotate anticlockwise
				rotateDir = 0;
			}
		}
		// IF ALERT IS NOT RAISED
		else
		{		
			// Sweep spotlight back and forth across 180 degree arc
			if (my.pan >= restPosition.pan +90)
			{
				// Rotate clockwise
				rotateDir = 1;
			}
			if (my.pan <= restPosition.pan -90)
			{
				// Rotate anticlockwise
				rotateDir = 0;
			}
		}
		
		// Rotate spotlight
		if (rotateDir == 0)
		{
			// Rotate anticlockwise
			my.pan += 2*time_step;
		}
		if (rotateDir == 1)
		{
			// Rotate clockwise
			my.pan -= 2*time_step;
		}


My code's probably a bit of a mess. But if anyone can offer any advice, it would be appreciated.

Also, another lesser problem: The Watch feature of SED. What do I type into it to make it watch a variable defined within an entity's action? This would make debugging my problems a lot easier.

Last edited by roBurky; 11/27/08 20:00.