.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   General Bot Coding (http://forums.bots-united.com/forumdisplay.php?f=24)
-   -   Having a bot face one way, while moving another (http://forums.bots-united.com/showthread.php?t=1709)

Maleficus 20-05-2004 01:14

Having a bot face one way, while moving another
 
Hellos!

I'd like to know what you guys think would be the best (cheapest, fastest) way to have a bot move in one direction, while looking in another.

Please understand that my question is for a Quake 3 engine based game (so any examples will have to be in C ;) ).

ATM, I basically just set the bots ucmd.angles to point to where ever its current goal is (waypoint, enemy, friend), and then set its ucmd.forwardmove to max (i.e. it turns to its goal, then runs forward).

botman 20-05-2004 01:28

Re: Having a bot face one way, while moving another
 
There is the body/facing angles and then there is the movement direction (forwardmove, sidemove, etc.).

Just set the facing direction to one angle and set the movement direction based on a different angle (or vector). Using a movement angle would make things easy since you could get the forwardmove and sidemove values just by using sin() and cos() on the movement angle.

botman

Maleficus 20-05-2004 01:37

Re: Having a bot face one way, while moving another
 
Quote:

Originally Posted by botman
Just set the facing direction to one angle and set the movement direction based on a different angle (or vector). Using a movement angle would make things easy since you could get the forwardmove and sidemove values just by using sin() and cos() on the movement angle.

botman

Thx for the quick reply!

However, one problem, my 3D math skills suck.

How would I get those forwardmove, sidemove values?

@$3.1415rin 20-05-2004 10:38

Re: Having a bot face one way, while moving another
 
dunno about quake3, maybe you can even set the movement direction by using a vector pointing to that direction or according pseudo polar coordinates ( 2 angles )

botman 20-05-2004 15:09

Re: Having a bot face one way, while moving another
 
sin() is used to find the Y axis direction and cos() is used to find the X axis direction (or if your axes are flipped, sin() for X and cos() for Y).

You would need to keep a bot variable (not in the edict) for the "direction angle" you want them to go. You can keep that in degrees if you aren't comfortable with radians (which is what sin() and cos() use as arguments). Let's say you call your "direction angle" variable 'a_dir' and you're keeping things in degrees (0-360). You could do something like this to set the forwardmove and sidemove values...
Code:

float radians = a_dir * 3.14159f / 180.f; // degrees to radians
float forwardmove = cos(radians);
float sidemove = sin(radians);
 
// now scale the forwardmove and sidemove values up by the
// speed you want to use since sin() and cos() return values
// between -1 and 1...
forwardmove = forwardmove * 100.0f;
sidemove = sidemove * 100.0f;
 
// then call the engine "move" function with your forwardmove
// and sidemove values as usual

Notice that you could move forward/backware at different speeds than sideways (by changing the 100.0f in the above code), you doing this would cause your movement angles to be skewed.

botman

Maleficus 20-05-2004 22:11

Re: Having a bot face one way, while moving another
 
Thx Botman!

I'll give that info a try :)


All times are GMT +2. The time now is 09:00.

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