.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   Half-Life 2 SDK (http://forums.bots-united.com/forumdisplay.php?f=62)
-   -   Yay - Bots move to given vector location... (http://forums.bots-united.com/showthread.php?t=3326)

stefanhendriks 03-01-2005 17:50

Yay - Bots move to given vector location...
 
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.

stefanhendriks 04-01-2005 23:48

Re: Yay - Bots move to given vector location...
 
so, did it work for anyone as well? (or any difficulties?). Or does this silence mean this post is uber l33t? :P

botman 05-01-2005 02:25

Re: Yay - Bots move to given vector location...
 
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

stefanhendriks 05-01-2005 09:45

Re: Yay - Bots move to given vector location...
 
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)

Cheeseh 05-01-2005 14:34

Re: Yay - Bots move to given vector location...
 
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 :P

stefanhendriks 05-01-2005 14:40

Re: Yay - Bots move to given vector location...
 
rofl yeah, well its good to keep on mailing them :D so far we made quite some progress imo in a 'short' amount of time :D

Cheeseh 06-01-2005 15:14

Re: Yay - Bots move to given vector location...
 
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.

stefanhendriks 06-01-2005 16:31

Re: Yay - Bots move to given vector location...
 
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?

Cheeseh 06-01-2005 17:00

Re: Yay - Bots move to given vector location...
 
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 ...

@$3.1415rin 06-01-2005 17:06

Re: Yay - Bots move to given vector location...
 
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) :)


All times are GMT +2. The time now is 07:45.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.