Jump to content
  • Advertisement

Archived

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

dawid

Running Away

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

  • 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!