Character Movement not moving how i want

Hi there and thanks for looking. I have some code right now that kinda works how i want. I want it to strafe left and right go back and forth. Things is when i press W he will always go forward no matter where my camera is facing. I want it to be where he fill go in the direction my camera is facing.

I am trying to get this controller to be like Ratchet And Clanks character controller so any help on how to do this or just help me with the above would be amazing.

I am trying to learn movements as they confuse the shizzle out of me. I do understand code very well but when it comes to this kinda thing it just goes over my head so any help with this would also be amazing.

Here is the code

using UnityEngine;
using System.Collections;

public class PlayerController : MonoBehaviour {

    private CharacterController controller;
    private Vector3 moveDirection;
    private Vector3 forward;
    private Vector3 right;
    public float speed;
	// Use this for initialization
	void Start () {

	    controller = gameObject.GetComponent<CharacterController>();
        moveDirection =;
        right =;
        forward =;
	// Update is called once per frame
	void Update () {
        // anhance this but leanr more as you go forward. Learn each statement so you know what it is 
        forward = Vector3.forward;
        right = new Vector3(forward.z, 0, -forward.x);
        float horizontalInput = Input.GetAxisRaw("Horizontal");
        float verticalInput = Input.GetAxisRaw("Vertical");

        Vector3 targetDirection = horizontalInput * right + verticalInput * forward;
        moveDirection = Vector3.RotateTowards(moveDirection, targetDirection, 200 * Mathf.Deg2Rad * Time.deltaTime, 1000);

        Vector3 movement = moveDirection * Time.deltaTime * speed ;
        float lookRot = Input.mousePosition.z;
        if (targetDirection !=
            Vector3 relativePos = transform.position - Camera.main.transform.position;
            float x, y, z;
            x = relativePos.x;
            y = 0;
            z = relativePos.z;
            Vector3 look = new Vector3(x, y, z);
            Quaternion rotation = Quaternion.LookRotation(look * Time.deltaTime * 2);

            transform.rotation = rotation;

Replace things like:

forward = Vector3.forward;
right = new Vector3(forward.z, 0, -forward.x);


forward = transform.forward;
right = transform.right;

Also, use the inverse of these for back/left:

backwards = -transform.forward;
left = -transform.right;

‘Vector3.forward’ will always return the same value, in this case (0,0,1). This means that ‘transform.position += Vector3.forward;’ will always move your object down the Z axis. As such, the direction variables within the Vector3 struct are always treated as world/global directions.

When you want the relative forward direction of an object (emphasis on relative), you obtain this from the objects transform as these values are unique to the object and so are contained within the objects unique transform information. ‘transform.forward’ will always be the forward facing direction of the object in question.

Yea i get what you are saying thanks man, Thing is i still don’t understand how it all works all i know is it kinda works. I want to know as much as possible with all this movement lark :stuck_out_tongue: