I am developing a 2D game where x is increasing rightwards and y downwards. Thus, the top-left corner is 0,0.
I have an enemy that moves towards a set of waypoints. When one is reached, it will start moving towards the next waypoint in the list.
I use the following code to move towards a point:
Vector2 norP = normalize(this.x, this.y, target.x, target.y);
float accelx = thrust * -norP.x - drag * vx;
float accely = thrust * -norP.y - drag * vy;
vx = vx + delta * accelx;
vy = vy + delta * accely;
this.x += delta * vx;
this.y += delta * vy;
That piece works fine. The problem is detecting when a point has been reached.
Right now, I use the following:
if(distance(this.x, this.y, target.x, target.y) < 25)
{
...
The value 25 is a fixed value and works sometimes. As you alter thrust and drag properties, the value 25 stops being effective.
So I need a formula that calculates this value that works good no matter what thrust and drag is(taking them into consideration).