#Pull (or subtract) "transform.forward" only from the Z axis

1 messages · Page 1 of 1 (latest)

tough summit
#

Hi there! I am currently trying to make a custom third person camera, and this is what I do to transform its position

transform.position = target.position - transform.forward * distanceFromTarget;

It works really well and I am happy with how it turned out, however the "distanceFromTarget" variable doesn't pull as expected if that makes any sense? I only want it to pull the position on the Z axis, nothing more, nothing less, is it possible to do this? I tried to subtract it using a Vector3 but as expected I couldn't because transform.forward is also a Vector, any help is appreciated, thank you!

snow loom
#

are you familiar with localspace and worldspace?

tough summit
snow loom
#

worldspace is the global xyz axis

#

localspace is the relative xyz axes to a gameobject

#

could you use these terms to describe how you want your camera to move?

#

i am confused what you mean by z

tough summit
#

Alright, so, when I multiply the "transform.forward" Vector by "distanceFromTarget" variable (which is 1.9f), it multiples all 3 axis (X, Y and Z) by it (so, 1.9f), is it possible to only make it multiply the Z axis of the camera by 1.9f instead of all 3 axis?

snow loom
#

that seems like a strange thing to do, but i can think of two options

you can use vector.multiply (this is a component wise multiplication) and multiply by (1, 1, distanceFromTarget)

you can save the forward vector to a variable, multiply only the z by distanceFromTarget, then use it in computation