View Single Post
Re: Having a bot face one way, while moving another
Old
  (#5)
botman
Super Moderator
 
Status: Offline
Posts: 280
Join Date: Jan 2004
Location: Plano, TX
Default Re: Having a bot face one way, while moving another - 20-05-2004

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

Last edited by botman; 20-05-2004 at 15:13..
  
Reply With Quote