#### Archived

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

# Running Away

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

## 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; } }

1. 1
2. 2
Rutin
18
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633701
• Total Posts
3013443
×