Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, Akow, degenerate_762), 1,430 guests, and 9 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19055 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Angle differences #238496
11/27/08 19:58
11/27/08 19:58
Joined: Nov 2008
Posts: 8
R
roBurky Offline OP
Newbie
roBurky  Offline OP
Newbie
R

Joined: Nov 2008
Posts: 8
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.
Re: Angle differences [Re: roBurky] #238517
11/28/08 00:11
11/28/08 00:11
Joined: Apr 2006
Posts: 737
Ottawa, Canada
O
Ottawa Offline
User
Ottawa  Offline
User
O

Joined: Apr 2006
Posts: 737
Ottawa, Canada
Hi! smile

Read on
% Modulo operator, the integer remainder of a division.

add this to your code for a limit of 360.
%360
// It has been posted before ...somewhere..

For debuging I make a panel with the variables that I want to follow.

Ottawa

Ottawa

Re: Angle differences [Re: Ottawa] #239403
12/04/08 15:01
12/04/08 15:01
Joined: Nov 2008
Posts: 8
R
roBurky Offline OP
Newbie
roBurky  Offline OP
Newbie
R

Joined: Nov 2008
Posts: 8
Thanks - With that information I could modify into lite-c a script I had for angle differences in another language.

Re: Angle differences [Re: roBurky] #239511
12/05/08 00:36
12/05/08 00:36
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
if you use
Code:
ang
it will keep the angle between -180 and 180

hope this helps


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1