Stumped by Cogs.

Stumped by Cogs.

Discuss game development here, from a distinct game project to an accessible third-party mutator, down to the interaction and design of individual units if you like.

Moderator: Moderators

Post Reply
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Stumped by Cogs.

Post by Argh »

Ok, trying to get Mael's contest turret to work, see the WIP thread if you need a visual aid.

The script is borked, and I'm stuck.

Here's what the script must do:

It has to rotate the two cogs 1/2 as much as the turret, along the x-axis. One cog goes one way, the other is opposite.

Sounds simple, eh? However, it's turning out to be rather difficult to actually achieve. Something is wrong with Spring, I think- the COBHandler code doesn't seem to get an update to Heading01 correctly, or something. Sometimes, it seems to operate correctly... other times, it doesn't even seem to run the cog part of the script until well after it has turned the Turret to the target. What's really irritating is the inconsistency of the way it's operating- first it does one thing, then another, and there doesn't seem to be a clear pattern here.

Anybody got any ideas?

Code: Select all

AimWeapon1(heading, pitch, HeadingNow, Tolerance)
{
	signal SIG_AIM1;
	set-signal-mask SIG_AIM1;

	Heading01 = heading;
	Pitch01 = pitch;
	
	if(LastHeading != Heading01) 
	{
		if(Heading01 <= 32768) 
		{
			HeadingNow = Heading01; 
		}
		if(Heading01 > 32768) 
		{
			HeadingNow = 0 - Heading01; 
		}		
		if(HeadingNow > LastHeading) 
		{
			Tolerance = HeadingNow - LastHeading;
			if (Tolerance > 1)
			{		
			turn cogs_l to x-axis 0 - HeadingNow / 2 speed <120>;
			turn cogs_r to x-axis HeadingNow / 2 speed <120>;
			}			
		} 
		if(HeadingNow < LastHeading) 
		{
			Tolerance = HeadingNow - LastHeading;
			if (Tolerance > 1)
			{	
			turn cogs_l to x-axis HeadingNow / 2 speed <120>;
			turn cogs_r to x-axis 0 - HeadingNow / 2 speed <120>;
			}
		}
		LastHeading = HeadingNow;
	}
  	turn turret to y-axis Heading01 speed <120>;	
 	turn aimer to x-axis 0 - Pitch01 speed <130>;
	wait-for-turn turret around y-axis;
	wait-for-turn aimer around x-axis;	

	start-script RestoreAfterDelay();
	return(TRUE);
}
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Post by Argh »

Headings should be returned as integers. I originally had Tolerance in there as a fudge number, thinking that maybe I could keep it from wiggling about and doing strange things by setting that up to the tolerance of the weapon (in theory, these values are the same, I think).

Right now, it's just a useless line, though- if I set it high enough, the cogs never spin at all, if I set it to 1, then ... well, they spin, but only sometimes, and sometimes well after the turret has finished rotating.

I'm starting to wonder if there's something screwy with the "always take the shortest turn" code- it almost seems like it's sending negative turnspeeds to the cogs, or something. But the outright delay is the biggest annoyance.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

Why are you switching the heading on the cobs depending on whether the aim is to the left or the right of the previous aim? Wouldn't that cause the wheels to turn a whole lot when you do a small correction to the left/right after moving right/left?
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Post by Argh »

Well, the problem is that every turn of the cogs has to be relative to the previous turn of the turret. If the turret is currently facing 45 degrees Y, and will end up at 135 degrees Y, the cogs need to rotate based on that 90-degree slice, not rotate 135 degrees from zero. You're probably on to something there, though- maybe I'm not calculating current rotation correctly. I thought I was storing that value from the previous rotation in LastHeading, though... hmm... I'll check this out after I've gotten some sleep.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

Hm, I think it might work to just see if you're rotating left or right and use spin instead of turn on the cogs.
User avatar
SinbadEV
Posts: 6475
Joined: 02 May 2005, 03:56

Post by SinbadEV »

I'm not sure if this idea will help but I was thinking it would be easier to cheat.

You Store 20 positions for the driver gears to be in instead of actively calculating the positions, then at any given time you only need to be moving from one position to another... which I haven't figured out yet... now the problem is that if you were to do it "correctly", you it takes 40 positions for all the pieces to return to the orriginal position so you could have the thing handle 40 positions, or you could just cheat again and have the driver gears reset to the first position at that point.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

I know there's some standard acceleration that gets applied to spin commands, did you set the acceleration high enough?
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Post by zwzsg »

I used no acceleration keyword, and expected the acceleration to be instant. But you're right, now that I take care of having proper accelerations, the turret works perfect: CogTurret2.sd7
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Post by Argh »

@zwzsg:

I'll give it a try and see if it works ok here in a day or two. Just released the Alpha to the modelers to bug-hunt.
Post Reply

Return to “Game Development”