Obviously the regular dist formula I’ve been using doesn’t work in this case:
[CODE] this.dx = this.destination[0]-x;
this.dy = this.destination[1]-y;
this.dist = (this.dx^2+this.dy^2)^.5;
if(this.dist>1){
x += (this.dx/this.dist)*this.speed;
y += (this.dy/this.dist)*this.speed;
}[/CODE]
With this, the object stops at the given point, I believe that getangle could help me out in this case but I know tricxta is way better in maths than I am, so before I spend the week trying to reinvent some wheel, I’m asking for help. Tnx
EDIT:
I figured it out thanks to google and this website.
[CODE] this.dx = this.destination[0]-x;
this.dy = this.destination[1]-y;
this.angle = getangle(this.dx,this.dy);
this.u = {cos(this.angle),sin(this.angle)};
x += this.u[0]*this.speed;
y -= this.u[1]*this.speed;
[/CODE]
EDIT AGAIN:
This is just another way of calculating the direction, in fact all I needed to do was set this.dx and this.dy in if(created), stupid me.
[CODE]if (created) {
this.destination = {playerx,playery};
this.dx = this.destination[0]-x;
this.dy = this.destination[1]-y;
this.speed = .5;
timeout = .05;}
if(timeout){
this.angle = getangle(this.dx,this.dy);
this.u = {cos(this.angle),sin(this.angle)};
x += this.u[0]*this.speed;
y -= this.u[1]*this.speed;
if(x<1||y<1||x>64||y>64) destroy;
timeout = .05;
}[/CODE]
Someone merge this in useful formulas so this kind of stupidity doesn’t show itself again X_X… sometimes all you need is a good night’s sleep… and a little luck.