Allegro.cc Forums » Programming Questions » Point A to Point B

 Cerpin Taxt Member #8,304 February 2007 Just trying to get a dot moving smoothly from predecided point A to moving, player-controlled point B. Because of the way I'm doing it, the dots stop just short of point B. I'd just like to know about any better ways of doing this.``` for( iRe2 = 0 ; iRe2 < n; ++iRe2) { iLX = (mouse_x-iEnemyX[iRe2])*0.1; iLY = (mouse_y-iEnemyY[iRe2])*0.1; iEnemyX[iRe2] += iLX; iEnemyY[iRe2] += iLY; circlefill( buffer, iEnemyX[iRe2], iEnemyY[iRe2], 2, makecol( 255, 0, 0 )); if( iEnemyX[iRe2] == mouse_x && iEnemyY[iRe2] == mouse_y ) return(0); } ``` Relevant code and exe attatched.I know it's because of the 0.1's at the end of the iLX and iLY lines.
 CursedTyrant Member #7,080 April 2006 ```float Angle = atan2f(B.Y-Dot.Y, B.X-Dot.X); Dot.X += cos(Angle)*Speed; Dot.Y += sin(Angle)*Speed; ``` I'm not sure if that's what you want tough... ---------Signature.----[My Website] | [My YouTube Channel]
 Kikaru Member #7,616 August 2006 Some example code: ```point get_speeds(point A, point B, int speed) { int xd = abs(a.x-b.x); int yd = abs(a.y-b.y); int td = int(sqrt((xd*xd)+(yd*yd))); td /= speed; yd /= td; xd /= td; point speeds(xd, yd); return speeds; } ``` This assumes you declared a struct/class called point, with member x and y. It also assumes you set up a proper constructor for that class.(P.S. sorry of it's really messy)