How to make my character move in his local z axis!?

Hi guys I know it sounds like a noob question … I am used to 2D games 3D is much confusing to me ^^

I have a character I want to move it toward his local z axis when a key is pressed? I can make it move’s in the global z axis but this is not what I need.

Also is there any simple script to make it aims to the cursors position? (i know the lookAt method but idk how to set it to the cursor!)

thanks in advance guys u r the best !

transform.forward is a gameObject’s local z axis. -transform.forward would be going backwards.

The LookAt method takes a Vector3; if you want to look at the cursor position, you can raycast from the camera towards the cursor position and use the hit.point as your Vector3.

public Vector3 cursorWorldPos;
public GameObject myObject;

void Update() {
     Ray mouseRay = Camera.main.camera.ScreenPointToRay (Input.mousePosition);
     RaycastHit hit;

     if(Physics.Raycast(mouseRay, out hit, Mathf.Infinity) == true) {
          cursorWorldPos = hit.point;
     }

     if(Input.GetMouseButtonDown(0)) {
          if(myObject == null) {
               Debug.Log("myObject is empty!");
               return;
          }
          myObject.transform.LookAt(cursorWorldPos);
     }
}