How to transform a vector to be relative to point?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By redstonecreeper8

Basically, I want to make the “down” direction go towards a point in space rather than the positive y axis. So for example, if an object is moving in the positive y direction but the “gravity point” is located just to the right of the object, their motion would be converted to the negative x direction from the POV of said point. If the object was moving in the negative y direction but the point was just above them, their motion would be converted to a positive y direction from the point’s frame of reference. I’m not sure if this makes any sense but if anyone knows how to do this, it would be greatly appreciated. Thanks! :slight_smile:

maybe draw it, it will be easier to help

Omicron | 2020-12-21 20:45

:bust_in_silhouette: Reply From: Lopy

If you have A and G two vectors (2D or 3D) representing points, the path from A to G is G-A. If G is your center of gravity, you have y = (A-G).normalized(). (Doesn’t work if A == G, as you’d divide by 0).

In 2D, x is easy, x = y.rotated(-PI/2).

But in 3D, I would use a Transform. First, get your Transform to the wanted orientation, and then use transform.basis.xform(Vector3.LEFT), and similar. (we use xform on the basis to discard any translation on the Transform).