Moving an object on a linear path? *RESOLVED*
I'm still working on my game, and I want a better movement algorithm than the current. It's a 2D tile based game, and the current algorithm works something like this:
VB Code:
'DestX and DestY refer to where the player clicked for the
'character to move, while CharX and CharY are the character's
'current position
Do Until CharX = DestX And CharY = DestY
If NewDest = True Then Exit Do
If DestX > CharX Then CharX = CharX + 1
If DestX < CharX Then CharX = CharX - 1
If DestY > CharY Then CharY = CharY + 1
If DestY < CharY Then CharY = CharY - 1
'draws the character in its new position
Call MoveCharacter(CharX, CharY)
Loop
That's no good because the character moves in a diagonal line until it reaches the same X or Y position as the destination, then moves in a straight line. I need the character to move in a diagonal line the entire time, heading towards the destination each turn.
My theory is this: Get the slope of the character's position and the destination's position each turn, and move the character according to the slope. This could work, correct? If not, then what's another theory? Thanks.