Game Development Community

How can a bot shoot???

by Martin Edmaier · in Torque Game Engine · 03/05/2002 (10:15 am) · 4 replies

Can anybody script that?
I don't know how script this function.

Thankx,

Martin

#1
03/05/2003 (12:23 am)
Good question. I'm using the latest head myself, and %botplayer.setImageTrigger($WeaponSlot,true) doesn't do a thing. I also tried to throw out the trigger state replication AIPlayer.cc's function getAIMove(), to no avail.
Still, I believe that setImageTrigger is the right way to do it, because it's also used to depress the trigger of a dead player.

So that's where I am now: My bots navigate complex maps properly, but they don't shoot. Go figure.
#2
03/05/2003 (2:39 am)
Hm, I got it working in C++, but I am not using the latest HEAD... I do use the "new" AIPlayer class, though...
this is what I got, not sure if it will work for you...
in AIPlayer::getAIMove()... after
Point3F headRotation = getHeadRotation();
         movePtr->pitch = newPitch - headRotation.x;
add:
// Following / Attacking / etc.
		if (mModeFire) {
			const char *WeaponSlot = Con::getVariable("$WeaponSlot");
			S32 slot = dAtoi(WeaponSlot);

			if (slot >= 0 && slot < ShapeBase::MaxMountedImages) {
				if (getMountedImage(slot)) {
					
					if (!movePtr->trigger[slot]) {
						// shoot trigger
						movePtr->trigger[slot] = true;
					}
				}
			}
		}
		if (mModeJump) {
			if (canJump()) {
				if (!movePtr->trigger[2]) {
					movePtr->trigger[2] = true;
				}
			}
		}
		// end Following / Attacking / etc.

And I have functions to set those bools:
/**
 * Tells the AI to fire.
 */
void AIPlayer::fireWeapon(bool enable) { // Jimomighty
   // Fire the seclected weapon.
	
	if(enable)
	{
		mModeFire = true;
		throwCallback( "onShoot" );
	}
	else
	{
		mModeFire = false;
		throwCallback( "onUnshoot" );
	}
}

/**
 * Tells the AI to jump.
 */
void AIPlayer::doJump(bool enable) { // Jimomighty
   // Fire the seclected weapon.
	
	if(enable)
	{
		mModeJump = true;
		mJump = true;
		throwCallback( "onJump" );
	}
	else
	{
		mModeJump = false;
		mJump = false;
		throwCallback( "onUnJump" );
	}
}

void AIPlayer::doJump() { // Jimomighty
	doJump(true);
}
You might wanna try that... the code is also in the last AI resource I've submitted, btw...

Oh, a question, Josef: you bots are able to navigate through maps? do you have pathfinding working? if so, I would be interested in the details, because I've just finished some pathfinding code for our AI... I'd like to hear how you have done it, if you don't mind.... :)
#3
03/05/2003 (2:53 am)
Many thanks for your code, I'll try that out later today when I get home.
EDIT: I somehow missed your resource back when you posted it... Dunno how I managed to not see it.

As for the pathfinding, I've done that all in script (lazy boy, I know). Still, it's very fast and I saw no need to bother with C code.

I've just submitted a complete resource, I hope it gets approved soon. Adding my scripts to your existing bot is dead-easy, it's just one function call and your bot starts heading down the maze :)
#4
03/05/2003 (8:34 am)
Ouch, I'm afraid the bots still don't shoot.
I tried setting movePtr->trigger[slot] = true but it doesn't do a thing!