Bots facing to Player?

Started by
1 comment, last by Daywalker313 22 years, 8 months ago
The bots in my game should be able to rotate until they face to a point, but i dont know how i could do it. They should easily adjust their heading in degrees until they face to the player (point), i dont need look up/down. Bot: x,z,heading Player: x,z I think that are enough informations to perform it. Could somebody please post the code, because i dont understand the vector/dotproduct stuff. Thanks
Advertisement
well , i know how to do it in 2D if it helps you...
email me if u need me.

velich@matavtv.net


"Thats who you are. Thats what you could."
------------------------------
- Goblineye Entertainment
------------------------------

------------------------------- Goblineye Entertainment------------------------------

If you only need to rotate a bot in the Y axis, knowing the x and z coordinates of the bot and the player, then that's a 2d problem.

bot.rotation = atan2(bot.z - player.z, bot.x - player.x);

Of course, this will be in radians. OpenGL accepts arguments in degrees (I don't know about Direct3d). So, depending on whether your rotation function takes degrees or radians, you may need to convert the return of atan2 to degrees. That is accomplished by multiplying by a conversion factor. That conversion factor is 180/PI . Similarly, if you ever need to convert degrees to radians, multiply by PI/180. Of course, multiplication by one is the same as division by the other.

Edited by - TerranFury on August 19, 2001 8:17:56 PM

This topic is closed to new replies.

Advertisement