1
\$\begingroup\$

I have two object in space, one has velocity (object A) with fixed magnitude, and one is static (object B).
every timestep, I add to object A's velocity a vector which direction is object A to object B, and then make the length of velocity back again (so after this addition, only angle changed), then I move object A using this new velocity (with its magnitude multiplied by fixed timestep), so at the next timestep, the additive vector will have different angle because object A had moved.

If I keep doing it every timestep, the angle between velocity vector of A and vector that goes from A to B will go toward (small enough) zero.
How do I calculate the magnitude of the additive vector so that the angle will go to zero after x seconds?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

I think you can't. With this approach your object A will always have a velocity with a small component in the original direction. Why don't you calculate the angle between the A's velocity and the direction vector towards B (via scalar product). You can then lower this angle each time step (fast enough so that it becomes 0 after X seconds) and calculate the new velocities and positions.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ since the angle will be different each timestep(because object A will move before next rotation of velocity vector), how do I compute how much rotation I need each timestep so that it will always reach zero? Is there a 'correct' way to do this? \$\endgroup\$
    – Rei
    Commented Aug 15, 2016 at 9:24
  • 1
    \$\begingroup\$ I don't think that there is an exact way to do this. It would requiring you to solve the differential equations of your system, provided that your game is solveable (which mist games are not). I think your best option is making the change in angle depending on the angle difference (the more the angle does not fit, the more you change it) until a threshold is reached where you simply set it to zero. This is the correct way if it yields the intended result. \$\endgroup\$
    – VoidStar
    Commented Aug 15, 2016 at 9:35
  • \$\begingroup\$ I just thought "hey, this is basically a homing missile!" and sure enough, there's already a question about this :p gamedev.stackexchange.com/questions/17313/… \$\endgroup\$
    – Rei
    Commented Aug 15, 2016 at 12:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .