Repel an object
by USC - IMD student 2 · in Torque Game Builder · 01/29/2007 (5:37 pm) · 3 replies
I want an Object A to move away from Object B. Specifically, Object B should move away in the opposite direction that the "moveTo" command would provide.
Yes, this is a trig question, not a TorqueScript question. Since I know the two objects' positions, how would you calculate the direction in which Object A moves?
Yes, this is a trig question, not a TorqueScript question. Since I know the two objects' positions, how would you calculate the direction in which Object A moves?
About the author
#2
01/29/2007 (6:19 pm)
Just thought of an alternate way. Calculate the vector from A to B, then subtract that vector from A's position. You can then normalize the vector or not, depending on what you need to use it to do.
#3
You just need the vector from B to A (A's position - B's position) and you can scale it however you want and apply it as a velocity to A. This is by far the simplest way.
02/01/2007 (7:28 am)
If you have the vector from A to B and subtract A's position, you would have the position in world space of A modified by it's distance and direction from B. If you normalized that and applied it to A it would move away from the origin (0, 0) radially away from B.You just need the vector from B to A (A's position - B's position) and you can scale it however you want and apply it as a velocity to A. This is by far the simplest way.
Torque Owner Ben R Vesco