I am unsure of a proper title for this post and haven't had luck finding a proper answer. The best way I can describe this is, I have two objects $A$ and $B$ where $B$ should move relative to $A$. To be more specific:
- The position for $A$ is always locked between $(0, 0)$ and $(W, H)$.
- Object $B$ should move with $A$ at certain times.
- Should also maintain its offset from $A$ from when movement began.
$A = (150, 50), B = (0, 0)$
$A$ moves freely for a while.
Event occurs that makes $B$ move with $A$.
$A = (250, 100), B = (0, 0)$
Offset is $(250, 100)$.
If $A$ moves to $(350, 200)$ then $B$ should move to $(100, 100)$.
If $A$ moves to $(150, 50)$ then $B$ should move to $(-100, -50)$.
I think the math behind this is:
$$B = A - B$$
But while testing it this causes jumping on $B$ and I'm not sure if the math I came up with is correct at this point. Is my math correct, or should I be doing something differently.
If the tags are incorrect, or additional tags would be better, please edit the post.