• Find a vector between 2 entities
    2 replies, posted
Hi, i need help finding vector between Entity №1 and Entity №2 All entities can move only in X and Y but Z is always 20, the only moving entity is №1, entity №2 is static. Example, (2D top-down perspective): https://i.imgur.com/fh91qHZ.jpg I know point A and C positions and now i need to get position from point B but it must be a 400 units closer to A, and also point B should stand strictly on the ray as shown in the example above. Goal is to move entity №1 to point B.
All you need to do is subtract A from C and you will get the vector representing the distance and direction between A and C. Then you can normalize this vector to a unit vector that you can multiply with 400. If you then add the resulting vector to point C you will get point B.
Here is what @Fredy said, in code: local A, C = entA:GetPos(), entC:GetPos() -- get the vector C->A local CA = A - C -- get the vector C->B (same direction as C->A, but absolute size (length) is 400) local CB = CA:GetNormalized() * 400 -- get point B local B = C + CB
Sorry, you need to Log In to post a reply to this thread.