Moving player in direciton camera is facing

Hello, i am making i space game like “Freelancer” or equivalent and i am working on the movement. My plan is that when the left and right arrow keys / A & D are pressed the character will spin on the horizontal axis, which it does, but when i move the mouse down so its facing the floor and then press the up / w i just goes like i am looking forward, i am wanting to go up if i am looking up but down if i am looking down. i have set the first person control camera script and took off the others so i just have camera movement and i have disabled gravity. i have this code;

var speed : float = 3.0;
var rotateSpeed : float = 3.0;

function Update () 
{ 
	var controller : CharacterController = GetComponent(CharacterController);
	
	// Rotate around y - axis
	transform.Rotate(Vector3.right, Input.GetAxis ("Horizontal") * rotateSpeed, 0); 
	
	// Move forward / backward
	var forward = transform.TransformDirection(Vector3.forward); 
	var curSpeed : float = speed * Input.GetKeyDown ("Vertical");
	controller.Move(forward * curSpeed);
}
@script RequireComponent(CharacterController)

sorry if my question is confusing but basically which ever direction the camera is facing i want when i press movement key it go in that direction.

thanks in advance

you will want to get the camera transform.forward and use that to base the characters movement on.
make a variable that stores the camera object:

var cameraObject : GameObject;

change this:

controller.Move(forward * curSpeed);
to:

controller.Move(cameraObject.transform.forward * curSpeed);

and assign the camera you want to use to the variable in the inspector :slight_smile: hope this helps you :slight_smile: