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

Running Away

Started by dawid Mar 6, 2004 at 3:01 PM 0 replies 350+ views
Original Post
dawid
dawid
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; } }
Spy

Topic Locked

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

Sign in to reply to this topic.