0
$\begingroup$

The Problem


I've been working on a (very basic) game project where a square attempts to evade being touched by the users mouse. I have gotten stumped by the following problem:

Assume the users mouse $M$ is attempting to click on the square $B$.

Given the speed of $M$, an angle along which $B$ should move, and the amount of time $B$ should move for, find the point $P = (x, y)$ which $B$ should move to.

What I've Tried


One possible solution to the speed problem is simple: The speed that $B$ should move at is given by the speed of $M$ multiplied by some difficulty factor $D$ in the range $(0, 1)$. Therefore, $S(B) = MD$.

What has me so stumped is the latter part: Where should $B$ move to?

After searching Google, I found this, with no explanation provided: $$x(t) = x + tv\cos a$$ $$y(t) = y + tv\sin a$$ $where$ $$[x] = [y] = [t, v]$$

I believe that multiplying by $t$ scales the amplitude so that we don't overshoot (the speed portion of the equation), $\cos a$ and $\sin a$ give us how far we should move, and of course $x$ and $y$ give us where we are at now. I believe that $v$ is equivalent to $D$ in my speed formula; it scales the amplitude such that $B$ doesn't move at the same speed as $M$. However, What does $[x] = [y] = [t, v]$ mean?

$\endgroup$
0
$\begingroup$

enter image description here

I'll assume $\alpha$ is the angle between the $Oy$ axis and the position (vector) of B, relative to M, setting the origin of the Cartesian system of axes in M.
We can also write that, initially, $tg$ $ \alpha = \frac{x}{y} $

If we decompose the vector in its horizontal and vertical component ($\vec{v_x}$, respectively $\vec{v_y}$), we can write $\lvert\vec{v_x}\rvert=v*cos(\alpha)$ and $\lvert \vec{v_y}\rvert=v*sin(\alpha)$ and, therefore, the equations of motion for the point, which are what you just presented, are: $$x(t) = x+ t*v_x = x + tv\cos a\text{, or }\cos \alpha$$

$$y(t) = y+ t*v_y = y + tv\sin a\text{, or }\sin \alpha$$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.