x


What is the meaning of Vector3.back?

What is the meaning of Vector3.back?

more ▼

asked Apr 05 '12 at 02:46 AM

supermaer gravatar image

supermaer
10 4 5 5

(comments are locked)
10|3000 characters needed characters left

3 answers: sort newest

It is shorthand for writing Vector3(0,0,-1)

more ▼

answered Apr 05 '12 at 07:46 AM

kolban gravatar image

kolban
1.9k 2 7

(comments are locked)
10|3000 characters needed characters left

Vector3.forward gives you a unit vector pointing along the z axis, or (0,0,1).

Vector3.back gives you the opposite, (0,0,-1).

Neither of these are necessarily useful on their own, but they can be very useful in tandem with other code.

Some simple examples:

//pos points 1,000 units down the z axis
pos = Vector3.forward * 1000f;

//bar equals foo with zeroed x and y components
bar = Vector3.Scale(foo, Vector3.forward);

//baz points down the z axis with length equal to foo's
baz = Vector3.forward * foo.magnitude;

Those examples don't necessarily make sense out of context, unfortunately. The more you know about vector math, the more apparent the utility of these values should be.

Remember that vectors express a direction and length. A unit vector, with length one, can be thought of as expressing a pure direction. That's very useful in game development.

more ▼

answered Apr 05 '12 at 03:07 AM

rutter gravatar image

rutter
9k 4 16

(comments are locked)
10|3000 characters needed characters left

There is no such command. Try instead -Vector3.forward. ;)

more ▼

answered Apr 05 '12 at 02:51 AM

Kleptomaniac gravatar image

Kleptomaniac
2.8k 8 12 21

It's not mentioned in the script reference, but this does compile and run for me in Unity 3.5.0f5:

Debug.Log(Vector3.back);
//output is "(0.0, 0.0, -1.0)"

Shame the reference isn't more up to date, really. = It's only as useful as it is authoritative, IMO.

Apr 05 '12 at 03:09 AM rutter

Actually it's deprecated. It was in Unity in the 1.x days. Obviously it's still technically in Unity, but not officially. Best not to use it. (Surprised it still works though.)

Apr 05 '12 at 03:12 AM Eric5h5

Wow, thanks for that! Just tested and Vector3.back is indeed the same as -Vector3.forward ... also tested with Vector3.left ... same as -Vector3.right. I would never have known ...

Apr 05 '12 at 03:19 AM Kleptomaniac
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x915

asked: Apr 05 '12 at 02:46 AM

Seen: 2440 times

Last Updated: Apr 05 '12 at 07:46 AM