Calculating co-ordinates

I have an image moving from point a to point b - both points are known.

At the moment I'm updating the co-ordinates by doing the following:

double speed = 1;

double angle = Math.atan((double)yDistance / (double)xDistance);

if(entryX > destinationX && entryY > destinationY)

{

travelX = -(Math.cos(angle) * speed);

travelY = -(Math.sin(angle) * speed);

}

There are 4 if (else if) statements depending on where they start in relation to the destination)

travelX and travelY are added to the x and y co-ordinates of the image.

Anyways, this is fine but it doesn't look so nice - depending on the angle (more noticable on bigger angles) there is a noticable 'stepping' occuring, i.e. it looks as though it's moving across then down then across then down instead of a smooth diagonal.

It's purely asthetic but how can I make the movement look smoother and...nicer?

[1176 byte] By [nealbo101a] at [2007-11-26 20:48:52]
# 1

1. Look up Math.atan2 - it handles those four cases for you.

2. Why make things so complicated? double dx=destinationX-travelX, dy=destinationY-travelY;

int distsqr=dx*dx+dy*dy;

if (distsqr<=speed*speed) {

travelX+=dx; travelY+=dy;

}

else {

double scale=speed/Math.sqrt(distsqr);

travelX+=dx*scale; travelY+=dy*scale;

}

YAT_Archivista at 2007-7-10 2:12:19 > top of Java-index,Other Topics,Java Game Development...
# 2
Thanks - I didn't know about atan2 and I'll have a look over the code you supplied in the morning, it's 11:00 here and I'm knackered :)Will the code you gave me prevent the jumpyness I described?
nealbo101a at 2007-7-10 2:12:19 > top of Java-index,Other Topics,Java Game Development...
# 3
Oh and for me travelX and travelY is how much my X and Y co-ordinates change by when my timer is called every 100msWould I need to change your code to be travelX = instead of travelX+= ?(And the same for travelY).
nealbo101a at 2007-7-10 2:12:19 > top of Java-index,Other Topics,Java Game Development...
# 4
> Would I need to change your code to be travelX = instead of travelX+= ?Yes, and you'll also need to ensure that (dx, dy) is the vector from the current position to the destination - presumably destinationX-entryX.
YAT_Archivista at 2007-7-10 2:12:19 > top of Java-index,Other Topics,Java Game Development...