Skip to main content
GameDev.net gamedev.net
🔒 Locked

Bots facing to Player?

Started by Daywalker313 Aug 19, 2001 at 12:16 PM 1 replies 1k views
Original Post
Daywalker313
Daywalker313
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
Xeno
Xeno
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------------------------------
TerranFury
TerranFury
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.