Anybody know how to move a sprite along a smooth path to another location? I know how to find the slope of the line between two points. What gives me trouble is reducing the numbers I get to create smooth motion.
Example: Gun shoots from Point A to Point B. Want shell to travel on something close to a straight line from one point to the other. I can make it work sometimes by making a loop and dividing repeatedly by 2 or 3 until both numbers are less than, say, 10 or 15. But, obviously flawed and doesn't always work, never very accurate and sometimes way off.
I wasn't sure if the code would help. The basic idea seems to be so flawed. Anyway...
After I get the slope of the line (using Y2-Y1 for the Y component, X2-x1 for the X component) I'm left with two numbers representing (I guess) the amount of X and Y I want to move the sprite to create, at least, the illusion of a smooth path.
If these numbers are like 70 and 9, I don't want to move my sprite by 70 and 9. That would look stupid. So I want to reduce them smaller numbers (slope as a fraction, then reduced, y'know) but same ratio. Eyeballing, 7 and 1 would work, but computer don't eyeball so well. So I used:
Do until ABS(SX1)<15 and ABS(SY1)<15 SX1=SX1/2:SY1=SY1/2 Loop
Generally, it kindasorta works, but not well when one number is really big. I guess that's obvious, right...divide and truncate eventually makes one X or Y=0 and, over long distance, that creates a huge error, miss the target.
I know this must be simple.
Thanks for your help.
PS- I could post whole game on Wiki space but it's a little raw.