I used quads for simplicity but they are actually gizmos icons.
When I move the quads on the z axis they naturally converge towards the center (like the left quad and the central one). The red quads represent the white ones shifted to z.
I’m looking for a way to move the x and y axes at the same time as the z axis so as to keep the figure in the same apparent position in Game View (like the right quad). In this case the red quad (which is a gizmos icon so it is not resized) is moved on the z axis but manually “corrected” on x and y and remains in the same position for those looking in Game View.
Using a gameobject moved to the gizmos icon position I tried to infer the new position in several ways, Vector3.Forward, transform.forward, transform.transformDirection, add or subtract Vector3, but had no luck.
Do you have any suggestions?
Hey, that’s some dogged good work there… but what you want is the delta vector between the camera and the thing.
So let’s say the cube is your thingy:
void Update()
{
Camera cam = .... (however you want to get this)
// compute "away" vector:
Vector3 away = cube.transform.position - cam.transform.position;
away = away.normalized;
// send cube away from camera
cube.transform.position += away * GoAwaySpeed * Time.deltaTime;
}
If you need it to move a certain controlled distance on Z, then scale GoAwaySpeed up by dividing by away.z. This would keep all departing objects in their same relative “planar” position as they go away, rather than going away spherically.
If you expect the camera to be rotated arbitrarily instead of pointing +Z all the time, then in order to do the final step in the paragraph above, you would leave ALL the code above the same but first inverse-transform the away according to the camera’s Transform.