-1
\$\begingroup\$

i have object which is moving to points in the screen each time the point ( call it B)
is moving to different place and object A follow its direction . Im using Linear interpolation and simple pythagoras equation to find the vector to point B
what i have problem now is to find the location where object A should stop when it In point B place point B its just x/y location . point b can be any where on the screen enter image description here

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Why don't you just use an if statement to check if the x and y coordinates are the same for both points and only move the object if they are not. \$\endgroup\$ Commented Jun 4, 2017 at 17:08
  • \$\begingroup\$ not that easy on the update loop function in millisecond the be over that B point also the Point B can move from place to place \$\endgroup\$ Commented Jun 4, 2017 at 17:10
  • \$\begingroup\$ Could you update the question to specify the nature of the challenge you're experiencing such that a mere coordinate/vicinity check doesn't work? \$\endgroup\$ Commented Jun 4, 2017 at 17:30

1 Answer 1

1
\$\begingroup\$

Unless you're running on extremely slow hardware or dealing with incredibly fast objects, checking per-frame should be fine as long as you aren't looking for an exact hit.

It's best to check the distance between A & B, then see when the point is within the radius. For example, if object 'B' is 3 units wide, check if the line between 'A' and 'B' is less than 1.5 units long. That would indicate a collision.

If you're using a 3D engine such as Unity, you can handle this using colliders.

If you MUST check for collisions 'between frames' calculate the line of the objects travel between where the object currently is, and where it will be (ie compare each new set of interpolated points with the previous set), and see if that line would have passed through a sphere or box centered around point B.

This is easier for 2D than 3D, but it can be done - see https://stackoverflow.com/questions/5883169/intersection-between-a-line-and-a-sphere for some examples.

Again, if you're using a 3D engine such as Unity, you can handle this using colliders and Physics.Raycast.

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.