Object Rotate with Camera

I have game where I have a rigid body cylinder on a terrain. I have the Main Camera in mouse orbit with the cylinder, (using the MouseOrbit.js with cylinder as target). I also added a script so when the ‘W’ key is pressed, the cylinder moves in one direction.

#pragma strict
var speed : float;
var target : GameObject;
function Start () {

}

function Update () {

if (Input.GetKey(KeyCode.W)){
    

    transform.Translate(-Vector3.forward*speed*Input.GetAxis("Vertical"));
}
}

What do I add to make the cylinder’s direction change with the camera’s direction so that the forward direction is pointing away from the camera. So basically it’s like a third person control.

So basically it needs to be like a third person player when ‘W’ is pressed, the cylinder needs to move away from the camera and the mouse changes the direction.

Thanks in advance.

Put the camera as a child of your player and it should work !

I have decided just to make ‘A’ and ‘D’ rotate the cylinder.

#pragma strict
var speed1 : float = 0.2;
var speed2 : float = 1;
var target : GameObject;
function Start () {

}

function Update () {
    if (Input.GetKey(KeyCode.W)){
        transform.Translate(Vector3.forward*speed1);  
    
    }
    if (Input.GetKey(KeyCode.D)){
        transform.Rotate(Vector3.up*speed2);  
    }
    if (Input.GetKey(KeyCode.A)){
        transform.Rotate(-Vector3.up*speed2); 
    
    }
}

However anymore input on how to solve this is very much welcomed.