Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Running Away

This topic is 5282 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

I need a unit to move to its new location and the following procedure does it for me except the unit goes past the target point regardless of whether the point is behind it or in front of it ,although this doensnt make sense cause if its infront of it and you go pas it then it is behinde you and the unit should go backward and zigzag all the time in between(infront of and then behind the point) The Problem is that float getxspeed(float x,float y,float tx, float ty) { float dx = x-tx,dy = y-ty; float sx=0; float sy=0; if (positive(dx) > positive(dy)) { sx = dx / positive(dx); sy = dy / positive(dx); } if (positive(dx) < positive(dy)) { sx = dx / positive(dy); sy = dy / positive(dy); } return sx; } void cUnit::update(int step) { bx = int(x); by = int(y); if (bx != tx) { xspeed = getxspeed(x,y,tx,ty)*step*0.1f; x+=xspeed; } if (by != ty) { yspeed = getxspeed(y,x,ty,tx)*step*0.1f; y+=yspeed; } }

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!