.:: Bots United ::.  
filebase forums discord server github wiki web
cubebot epodbot fritzbot gravebot grogbot hpbbot ivpbot jkbotti joebot
meanmod podbotmm racc rcbot realbot sandbot shrikebot soulfathermaps yapb

Go Back   .:: Bots United ::. > Developer's Farm > SDK Programming discussions > Half-Life 2 SDK
Half-Life 2 SDK For developments focused around the Half-Life 2 engine Half-Life 2

Reply
 
Thread Tools
Yay - Bots move to given vector location...
Old
  (#1)
stefanhendriks
RealBot Author
 
stefanhendriks's Avatar
 
Status: Offline
Posts: 3,088
Join Date: Nov 2003
Location: Netherlands
Default Yay - Bots move to given vector location... - 03-01-2005

It took a bit of fiddling , but i got it working, so here a little tutorial to get it working for you too (based on botmans template), its not completely step by step, but it has lots of code snippets.

first, make sure the viewangles get updated by WriteUserCmd in the hpb_bot2_usercmd.x file:

Code:
// THIS IS OLD....
// buf->WriteOneBit( 0 ); // viewangles[0]
// buf->WriteOneBit( 0 ); // viewangles[1]
// buf->WriteOneBit( 0 ); // viewangles[2]
 
	// Viewangles - THIS IS NEW
	buf->WriteOneBit( 1 );
	buf->WriteBitAngle( cmd->viewangles[ 0 ], 16 );
	buf->WriteOneBit( 1 );
	buf->WriteBitAngle( cmd->viewangles[ 1 ], 16 );
	buf->WriteOneBit( 1 );
	buf->WriteBitAngle( cmd->viewangles[ 2 ], 8 );
ok, that will make life a bit more easier

So, first we need a vector in the bot_t so we get our bot moving to that vector constantly. Since the usercmd calls them viewangles (which is NOT correct) , i call it vViewVector.

Code:
typedef struct
{
edict_t* edict;
float fCreateTime; // time bot was created
float fJoinTime; // time when bot should do stuff to join the game (select team, etc)
 
 
	int		 iTeam;		 // the time the bot should join
								// FIXME: make it also change when team is forced to another
								//		so it can be used for knowing which team ur on.
 
	Vector vViewVector;
 
} bot_t;
 
 
// AND in CreateBot
 
// STEFAN:
	pBot->vViewVector = Vector(0,0,0);
Ok, so now we have the viewvector, we need a function to calculate the correct angles to get them in the usercommand... this function is called VectorAngles, and is located in mathlib.* (in public/) , though you cannot use them, they give compile errors which i was not able to fix, so what i did, i ripped it and removed the FastSqrt , replaced it with the (slow)/normal sqrt, and wham we got our own function. So copy this piece of code at the TOP (above the BotRunPlayerMove function):

Code:
//-----------------------------------------------------------------------------
// Forward direction vector -> Euler angles
//-----------------------------------------------------------------------------
// COPIED FROM MATHLIB.CPP - STEFAN
void UTIL_VectorAngles( const Vector& forward, QAngle &angles )
{
// Assert( s_bMathlibInitialized );
float tmp, yaw, pitch;
 
if (forward[1] == 0 && forward[0] == 0)
{
yaw = 0;
if (forward[2] > 0)
pitch = 270;
else
pitch = 90;
}
else
{
yaw = (atan2(forward[1], forward[0]) * 180 / M_PI);
if (yaw < 0)
yaw += 360;
 
		// STEFAN: use normal sqrt
tmp = sqrt (forward[0]*forward[0] + forward[1]*forward[1]);
pitch = (atan2(-forward[2], tmp) * 180 / M_PI);
if (pitch < 0)
pitch += 360;
}
 
angles[0] = pitch;
angles[1] = yaw;
angles[2] = 0;
}
go to the BotRunPlayerMove function that botman created; and get this before the processusercmd function:

Code:
	if (pBot->vViewVector != Vector(0,0,0))
	{
		UTIL_VectorAngles( pBot->vViewVector, cmd.viewangles );
 
		// clamp the pitch and yaw (as seen in the sdk)
		if (cmd.viewangles[0] > 180)
			cmd.viewangles[0] -= 360;
		if (cmd.viewangles[1] > 180)
			cmd.viewangles[1] -= 360;
}
now, to get a bot going where you want it to go, lets say you have vector vDir, you have to do this:

Code:
					Vector botVec=Vector(0,0,0);
					gameclients->ClientEarPosition( pPlayerEdict, &botVec );
					vDir = vDir - botVec;
					pBot->vViewVector = vDir; // ugly hack to set viewdir
so:
1. get the bot vector itself
2. substract your vector with the botvector
3. and finally set vViewVector to vDir

* EDIT:
Let me know if it does , or does not, work for you. I could have forgotten something.

NOTE:
THe bots do not LOOK at the direction, they MOVE at the direction, given the forward speed of the usercmd. (there is no sidespeed set, etc).

I am still looking for a proper 'looking' function.


Author of RealBot, "Arrakis" and "Dune 2 - The Maker" | co-Founder of Bots-United | Fundynamic | Blog | E-Mail me

Last edited by stefanhendriks; 03-01-2005 at 17:52..
  
Reply With Quote
Re: Yay - Bots move to given vector location...
Old
  (#2)
stefanhendriks
RealBot Author
 
stefanhendriks's Avatar
 
Status: Offline
Posts: 3,088
Join Date: Nov 2003
Location: Netherlands
Default Re: Yay - Bots move to given vector location... - 04-01-2005

so, did it work for anyone as well? (or any difficulties?). Or does this silence mean this post is uber l33t?


Author of RealBot, "Arrakis" and "Dune 2 - The Maker" | co-Founder of Bots-United | Fundynamic | Blog | E-Mail me
  
Reply With Quote
Re: Yay - Bots move to given vector location...
Old
  (#3)
botman
Super Moderator
 
Status: Offline
Posts: 280
Join Date: Jan 2004
Location: Plano, TX
Default Re: Yay - Bots move to given vector location... - 05-01-2005

I was able to get them to move in the proper YAW direction once I added the viewangles stuff (but I was just setting the YAW directly via a ClientCommand thing I added so that I could change it on the fly).

I looked through the SDK dlls code a bit to try to determine what sets the facing direction properly, but never found it.

I won't have time to look at this stuff again until probably late February or early March.

botman
  
Reply With Quote
Re: Yay - Bots move to given vector location...
Old
  (#4)
stefanhendriks
RealBot Author
 
stefanhendriks's Avatar
 
Status: Offline
Posts: 3,088
Join Date: Nov 2003
Location: Netherlands
Default Re: Yay - Bots move to given vector location... - 05-01-2005

i just hope the looking will be also 'as easy' because frankly i havent seen anything that will help me just yet. I try to find some info on a'fire a bullet' function so i know how they calculate it, but without getting the SDK compiled 100% properly under MSVC i am stuck with searching through files with Windows Commander (which is slow. :S)


Author of RealBot, "Arrakis" and "Dune 2 - The Maker" | co-Founder of Bots-United | Fundynamic | Blog | E-Mail me
  
Reply With Quote
Re: Yay - Bots move to given vector location...
Old
  (#5)
Cheeseh
[rcbot]
 
Cheeseh's Avatar
 
Status: Offline
Posts: 361
Join Date: Dec 2003
Location: China
Default Re: Yay - Bots move to given vector location... - 05-01-2005

I gave alfred an email about how to get "EyeAngles" without CBaseEntity/CBasePlayer, just the edict. I'll see if he gives a response, or the bot documentation for the SDK will be released before then
  
Reply With Quote
Re: Yay - Bots move to given vector location...
Old
  (#6)
stefanhendriks
RealBot Author
 
stefanhendriks's Avatar
 
Status: Offline
Posts: 3,088
Join Date: Nov 2003
Location: Netherlands
Default Re: Yay - Bots move to given vector location... - 05-01-2005

rofl yeah, well its good to keep on mailing them so far we made quite some progress imo in a 'short' amount of time


Author of RealBot, "Arrakis" and "Dune 2 - The Maker" | co-Founder of Bots-United | Fundynamic | Blog | E-Mail me
  
Reply With Quote
Re: Yay - Bots move to given vector location...
Old
  (#7)
Cheeseh
[rcbot]
 
Cheeseh's Avatar
 
Status: Offline
Posts: 361
Join Date: Dec 2003
Location: China
Default Re: Yay - Bots move to given vector location... - 06-01-2005

Alfred replied to say that you can only change eye angles if you have access to CBasePlayer (as botman said :p) They're working on how to access eye angles through plugins but have no date.
  
Reply With Quote
Re: Yay - Bots move to given vector location...
Old
  (#8)
stefanhendriks
RealBot Author
 
stefanhendriks's Avatar
 
Status: Offline
Posts: 3,088
Join Date: Nov 2003
Location: Netherlands
Default Re: Yay - Bots move to given vector location... - 06-01-2005

cheeseh, i tried ur code , but though i could not test it myself. Asp tried it for me , and he said it did not work? Are you sure it works for player entities as well?


Author of RealBot, "Arrakis" and "Dune 2 - The Maker" | co-Founder of Bots-United | Fundynamic | Blog | E-Mail me
  
Reply With Quote
Re: Yay - Bots move to given vector location...
Old
  (#9)
Cheeseh
[rcbot]
 
Cheeseh's Avatar
 
Status: Offline
Posts: 361
Join Date: Dec 2003
Location: China
Default Re: Yay - Bots move to given vector location... - 06-01-2005

The origin code? It works for me as a player, maybe it doesn't work for bots. I haven't tried it for getting bots origins though ...
  
Reply With Quote
Re: Yay - Bots move to given vector location...
Old
  (#10)
@$3.1415rin
Council Member, Author of JoeBOT
 
@$3.1415rin's Avatar
 
Status: Offline
Posts: 1,381
Join Date: Nov 2003
Location: Germany
Default Re: Yay - Bots move to given vector location... - 06-01-2005

the bots with stefans code ran always towards this corner at the ct spawn in de_cbble near to that bomb site and that fence there. dunno the coordinates yet there, but I wouldnt be surprised if there would be (0,0,0)


  
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com