Game Development Community

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?

#1
01/29/2007 (6:12 pm)
Get the angle from A to B, then add 180 degrees to it. That would be the simplest way. If you're unsure about how to do this I suggest typing
trig right triangle
into Google and following a few tutorials. They should give you everything you need!

#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
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.