The title is a little bit hard to understand, so, obviously, I’ll explain.

Lets say that I have a cube and a sphere. I want the cube to be a certain distance from the sphere when I go near it.

So I move the cube towards the sphere, the cube has a ray that senses the sphere. Once the cube senses the sphere the cube gets positioned exactly 10BU on the Y axis away from the sphere. So if I used the getDistanceTo function it would read 10.

How can I do this? I think I asked a question like this before but here’s the problem, it seems easy, but to me it’s not.

For example, the cube is 5BU away from the sphere, the ray senses the sphere, I set the position of the cube to the sphere and then -10 from the y position. This should work right? Well it does, but only the world position, so -10 doesn’t make the cube move backwards, it moves the cube -10 spaces on the Y.

Here’s a diagram:

The red arrows are the local -Y axis. Green arrows is the global -Y axis. How do I make the cube move along the red lines? So in my case it’s backwards. So basically I want the cube to move backwards according to where it’s facing which is the rotation…

Any ideas?