Jump to content
  • Advertisement
Sign in to follow this  
bigbrother2000

how do i calculate the X and Z of an object position when it is moving?

This topic is 4828 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, i have an object who is an enemy, currently it constantly looks at the player by rotating the Y angle of the object with the code below. However now i want it to always move towards the player's x,y,z position, however i am only able to change the x,y,z of the enemies position. Is there any calculations i can use to change these values so the enemy moves closer to the player a a certain amount each frame, such as 2 units closer each iteration. Any help would be appreciated, The look at code in use: XDiff = m_ReceptionObject.GetXPos() - m_CharacterObject.GetXPos(); ZDiff = m_ReceptionObject.GetZPos() - m_CharacterObject.GetZPos(); Direction3 = (float)atan2(XDiff, ZDiff); m_ReceptionObject.Rotate(0.0f,Direction3,0.0f);

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Quote:
Original post by bigbrother2000
Hello, i have an object who is an enemy, currently it constantly looks at the player by rotating the Y angle of the object with the code below. However now i want it to always move towards the player's x,y,z position, however i am only able to change the x,y,z of the enemies position. Is there any calculations i can use to change these values so the enemy moves closer to the player a a certain amount each frame, such as 2 units closer each iteration. Any help would be appreciated,

The look at code in use:

XDiff = m_ReceptionObject.GetXPos() - m_CharacterObject.GetXPos();
ZDiff = m_ReceptionObject.GetZPos() - m_CharacterObject.GetZPos();
Direction3 = (float)atan2(XDiff, ZDiff);

m_ReceptionObject.Rotate(0.0f,Direction3,0.0f);





You mean like using a unit vector based on that direction angle (facing of enemy)

x = x + sin(Direction3) * enemyspeed;
z = z + cos(Direction3) * enemyspeed;

??????

(you may want to prorate the enemyspeed by the framerate....)


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!