Accessing a variable inside of a different object

Hey guys,

I’m ripping my hair out on this one, it’s so aggravating! Basically I want to find the direction that the Z axis is pointing on the camera.

Scenario: Creating a FPS character movement script (don’t want to use the standard one, a year of programming in Game Maker has taught me to always code my own engines :smile:). my objects are made up of 2 objects, a capsule (the actual mover) and the camera. obviously the capsule is the parent of the camera. When I press the W key the capsule needs to move in the direction the camera is facing (in other words, the z axis of the camera) and I can’t get it -.-

here are my fruitless attempts at this O.o (its javascript btw)

var camObject : Transform;
var forwardDir = camObject.forward;

function Update () {
print (forwardDir);
}

Probably to you Unity experts this is a simple n00b mistake but to me, it’s a nightmare :smile:

thank you,
why789

var camObject : Transform;
var forwardDir : Vector3;

function Update () {

    forwardDir = camObject.forward;
    print (forwardDir);
}

Make sure you assign camObject as well.

ahh ok I see now :slight_smile: thank you!!