- Home /
Move object towards an angle the distance of two points
This issue has haunted me the whole day now and I'm quite irritated that I cannot figure out how to solve it.
I have two objects; Object_A and Object_B. I need to calculate the angle between them and then move Object_B the distance between Object_A and Object_B towards the calculated angle.
I hope it makes sense.
You mean move Object A toward Object B? $$anonymous$$aybe a diagram would help explain.
I'll try to explain it with this image:
The angle is quite obvious here but that will not always be the case. B needs to move the distance between A and B, towards the direction A->B.
Answer by Dave-Carlile · Jul 21, 2015 at 09:53 PM
I think this? But I can't test it right now.
Vector3 newPosition = b + (b - a);
b - a
gives a vector that points in the right direction, for the right length. So you should just be able to add it to b to get the new position.
Zomg. It works... Although I had to use a + (a - b). And obviously I have no idea why :)
I'm not sure I understand why your solution works. $$anonymous$$ath is not really my thing ;)
Thanks for the help!