# Can someone help me understand world/local space?

Everytime I think I understand it something comes up and I get confused again.

So say I have this code:

``````var coconutObject : Rigidbody;
var throwForce : float;

function Update () {

if(Input.GetButtonUp("Fire1")){

var newCoconut : Rigidbody = instantiate(coconutObject,transform.position,transform.rotation);

newCoconut.rigidbody.velocity =
transform.TransformDirection(Vector3(0,0, throwForce));
``````

The documentation says it transforms local into world. Alright. But say I’m adding this to an fps controller so and I want it to shoot coconuts in my forward direction. Shouldn’t making it into world space, like the TransformDirection does, always make it always go to the WORLD’S z and not the local z?
So basically no matter where I turn my character, it should always shoot the coconuts in in the same direction, because they’re going forward in the world’s z. But it does the opposite! It shoots the coconuts depending on where I turn, but wouldn’t that be local z? Because unlike the world z, my local z will always change depending on where i’m turning.
Instead, when I DON’T use the TransformDirection, it ALWAYS goes in the same direction.
This has been annoying me for a while now and I really want to get this down so I can better understand what i’m doing with unity.

rigidbody.velocity is stored as a World Direction
So you Just want to feed it Vector3(0,0,1);

When you use transform.TransformDirection its Asking for a LocalSpace Direction (which you are feeding it a Local Direction of Vector3(0,0,1); and Its converting it into a WorldSpace Direction, basicly, the way your character is Facing.

Another way to put this is~

the Vector3 Struct doesn’t know weather its a World Direction, World Position, Local Position, or Relative Direction. it just holds and X,Y, & Z

You have to keep track of what you Vector3 vars are holding…

I hope that makes some sence

And ultimately, just do this:

``````newCoconut.rigidbody.velocity = new Vector3(0,0, throwForce));
``````