Moving a character in relation to camera position?

Hi everybody,

I’m following some tutorials on creating a game from scratch. I’ll paste the character movement script below. It takes input from a player input script and mob AI script to control your player and mobs, respectively.

I’ve been trying to modify the movement to move my character forward backward left right always in relation to the camera. Cant quite seem to get it to work. I’m using snippets from Unity’s ThirdPersonController to help me but I’m stuck.

EDIT: I keep cutting this down so the script looks less daunting, I think thats why I’m getting no replies. I’m sure the answer is a quick edit of the script I have left below though.

Thanks!

Here’s the script I’m attempting to modify:

    using UnityEngine;
    using System.Collections;
    
    [RequireComponent (typeof(CharacterController))]
    public class AdvancedMovement : MonoBehaviour {
    	public enum State {
    		Idle,
    		Init,
    		Setup,
    		Run
    	}
    	
    	public enum Turn {
    		left = -1,
    		none = 0,
    		right = 1
    	}
    	public enum Forward {
    		back = -1,
    		none = 0,
    		forward = 1
    	}
    	
    		Init();
    	}
    	
    	private void Init(){
    		if(!GetComponent<CharacterController>())return;
    		if(!GetComponent<Animation>())return;
    		
    		_state = AdvancedMovement.State.Setup;
    	}
    	
    	private void ActionPicker(){
    
    			_myTransform.Rotate(0, (int)_turn * Time.deltaTime * rotateSpeed, 0);
    
    			if(_controller.isGrounded || _isSwimming) {
    				airTime = 0;
    				
    				_moveDirection = new Vector3(0, 0, (int)_forward);
    //				_moveDirection = Vector3.forward * Input.GetAxis("Move Forward");
    				_moveDirection = _myTransform.TransformDirection(_moveDirection).normalized;		//returns a vector of length 1 which we are trying to move
    				_moveDirection *= walkSpeed;
    			
    				if(_forward != Forward.none){
    					if(_isSwimming){
    					Swim ();
    					}
    					else{
    						if(_run){
    							_moveDirection *= runMultiplier;
    							Run();
    					}
    						else{
    							Walk ();
    						}
    					}
    
    				}
    				else{
    					if(_isSwimming){
    						Swim();
    					}
    					else
    						Idle ();
    				}
    			
    				
    	public void MoveMeForward(Forward z){
    		_forward = z;
    	}
    	
    	public void RotateMe(Turn y){
    		_turn = y;
    	}
    }

If you mean having the camera follow the player, you can aimply attach the camera to the player, and position the angle to your degree of desire.

Or am I misunderstanding your question.?