## Articles on moving object from point A to point B?

Problems with Canvas, OpenGL, etc...

### Articles on moving object from point A to point B?

Hello,

I am messing around with an icon i placed on the screen. I have it starting at the exact middle of the screen, and what I want it to do is when I place my finger on a certain location, it will travel to that spot and stop.

This was my thought process going into this...
We have the starting position, (origX, origY)
We have the destination, (destX, destY)
And we have the offset, will get added onto the objects position on each loop through, (xOff, yOff)

What I did with these two is as follows
calculate the gap between the two X's and the two Y's
gapX = Math.abs(origX - destX);
gapY = MAth.abs(origY - destY);

If (gapX > gapY){
xOff = 1;
yOff = gapY / gapX;
}else{
xOff = gapX / gapY;
yOff = 1
}

And then finally I am just checking if the offsets need to be negative and multiplying times -1 if needbe.

This kinda works. What I would like from anyone here is possible some links to some articles on doing things like this. I am assuming there is a better way than what I have attempted. Any help would be appreciated, thank you for your time.
-Nick

Nick Thomas
Freshman

Posts: 2
Joined: Thu Jun 16, 2011 5:20 am

### Re: Articles on moving object from point A to point B?

You'll definitely want to move to time based animation so that iterative distances are constant based on a time differential otherwise stuttering may occur or different devices may perform differently with variance between each rendered frame. You can add smoothing, so the icon accelerates and decelerates as it starts / approaches it's destination; a quick and useful approach is using Math.log1p() to create an accel / decel feedback loop. Feedback loops in general give an interesting way to make it look more natural in determining direction. An article on feedback loops for control systems is in this old version of Game Developers Magazine:
http://www.gdmag.com/archive/jun-jul04.htm
Founder & Principal Architect; EGR Software LLC
http://www.typhonrt.org
http://www.egrsoftware.com

MichaelEGR
Senior Developer

Posts: 147
Joined: Thu Jan 21, 2010 5:30 am
Location: San Francisco, CA

### Re: Articles on moving object from point A to point B?

Thanks for the timely response. I see it wants to charge me 3 dollars to read that issue however o_O
I will just look into feedback loops and time based animation.
Thanks again!
-Nick

Nick Thomas
Freshman

Posts: 2
Joined: Thu Jun 16, 2011 5:20 am