AI Tutorial
Decending Stairs

 

      The jumping AI of the tutor bot has always been pretty poor. RiEvEr's improved jumping AI code improved the matter somewhat, but it didn't take into account one of the most annoying problems displayed by most bots. That is, it doesn't walk down stairs.
      You must have noticed, that when confronted with a staircase, the bot leaps down it instead of running down. This is because both coffee's and RiEvEr's jumping code work by checking a distance ahead and below the bot, which can either mean that there is a ledge in front of the bot, or a ramp or stairs. Luckily, I've written some code to sort out this problem once and for all.
      Ok then, I'm assuming that you've already completed the 'Better Jumping For Sure!' tutorial, else this tut won't work too well. Open up tutor.qc and scroll down to check_for_ledge, which will now begin like so:


//RiEvEr
// BETTER JUMPING FOR SURE!
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
float() check_for_ledge =
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Return values:
// 0 = NOJUMP
// 1 = JUMP
{
	local   float   contents;
	local   vector  start, end;

	makevectors (self.angles);

// movetogoal() will never move over a ledge, so we have to 
// check for a break in front of him and force him to jump

	if (self.jumpin)
		return(0);

	// Where the bot's feet are now
	start = self.origin - '0 0 24';
	end = start + v_forward *96;

	// Check 96 Quake units in front of the bot at foot height
	traceline (start, end, TRUE, self);

	// If there's a wall or obstacle, return NOJUMP
	if (trace_fraction != 1.0)
		return (0); // NOJUMP

	start = end;
	end = start - '0 0 256'; //256 units down 

	// Now look down and see how far we drop and what's there (MAX 256 units)
	traceline (start, end, TRUE, self);

	contents = pointcontents (trace_endpos);
	// If it's LAVA, SLIME or a long way down and no ledge to jump to, return DANGER
	if ( (trace_fraction == 1.0) || (contents == CONTENT_LAVA) || (contents == CONTENT_SLIME) )
		return (0); // NOJUMP


      Now we'll stick in my stair checking code here, in the jumping ai. Paste in the following right there:

//      SkinSki stair decending code - START

	start = self.origin - '0 0 24';
	end = start + v_forward * 48;

	traceline (start, end, TRUE, self);

	start = trace_endpos;
	end = start - '0 0 50'; //50 units down 
	traceline (start, end, TRUE, self);

	if (trace_fraction != 1)
		return(0);

//      SkinSki stair decending code - END

      This does a couple of things. Firstly, it runs a traceline 48 units forward from the bot's feet. Then, it traces 50 units down from there. If it touches ground, it assumes it has found a step or ramp. It's not too complex really.
      That's the end of another simple but useful tutorial.

 


What We Learned

1. These tutorials are slowly hacking down the tutor bot's weaknesses
2. Even the best jumping AI can be improved
3. Only dull bots jump down stairs they could run down


Author: SkinSki
Questions: skinski@email.com
AI chat on ICQ: 30578982