How does point A calculate position of a moving point B when only "direction" of point B is known?

178 Views Asked by At

I am currently designing a game. I have a "runner" and a "catcher" that sort of play tag with each other. The catcher always know in which direction the runner is, but he does not know where exactly the runner is. This is critical for the game. The catcher is supposed to figure out, just from the "ray" that extends from the player to the catcher, where exactly the runner is. Like, a point in 2D space.

For now, I just have my program getting that information from the "runner's" position, since I can access it if I want to. But that got me thinking about how one would actually calculate that...

How in the world would someone calculate that? I looked it up and after a long time, I got to this TMA algorithm which is amazingly exactly what I want. But I don't understand it at all. Meaning, I totally understand the concept, but when I go to the whiteboard... nothing. When I read the math, I just don't understand what the variables represent or what they mean.

Can someone explain to me how I would program something like this? If I were to assume that the catcher and runner are two points in 2D space (that are not colliding with each other), and the catcher always has the bearing of the runner, but does not know anything else, and we can assume the runner is always running in that same direction (won't randomly change directions) and won't change his speed, what is the formula I should use for the catcher to calculate the point where the runner is? Of course, this needs to be a formula "over time", right? If you have an answer, can you also somewhat explain the formula? I am sure if it looks anything like the wikipedia page's formula's, I will reamin with zero understanding.

I was thinking this is just a basic trig question, but it's turned out to be way more complex and I've been scratching my head at this forever. Help..?

1

There are 1 best solutions below

0
On

Alrighty, I see it after 3 years but I hope it helps someone.

You start off with knowing just 2 positions. I will call them A and B, you can interpret them as you wish. A shooter, defender, or a runner a catcher.

Let's first start with getting a direction to the "X" (X being where will they meet). If you shoot a bullet where the bullet will meat the enemy like for example in a tower defense game.

You get the Vector AB (B-A). What else do we know? We obviously know the direction the B is going.Direction B is heading - B gives us BX Vector.Now we can calculate the vector from A to X by saying AX = AB + BX .

Good, so far we have almost everything we need to know. Let's actually see what is left. What is left is to know the length of the vector. I know the direction the enemy is going to be but after what amount of time ? What is my length?

Let's begin the meaty part.|AX| = |AB + BX|. We know one more thing and this is the speed of the projectile (A) and the speed of the defender(B) (Speed of runner and catcher). With the upper written formula, we end up having S.T = |Vb.T + AB|. ST comes from the length of this path, is the Time multiplied by the speed.S standing for speed here. (S = V.T , V=60KM T=1Hour , If we travel with this speed for 2 hours we would pass 120KM). So picking up where we ended we have S.T = |Vb.T + AB|.

  1. S.T = SQR((Vbx.T+ABx)^2) + SQR((Vby.T+ABy)^2)
  2. S^2.T^2 = (Vbx.T+ABx)^2 + (Vby.T+ABy)^2 (X AND Y FOR 2D)
  3. From here u have a D > 0 x1,x2 and you can calculate the T. Knowing the time gives everything else like a puzzle.
  4. Keep in mind negative time is where the B Was before in time. Positive means where will it be.

I hope it helps :)