Moving In World Space

Ok so i have my basic movement. Up down left right, but since i have mouse follow on, it changes its up down left right to the mouse cooardinates. (Ex : If i put the mouse to the right, Up moves right, right moves down, left moves up. down moves back.) So how would i have it move in world space no matter what direction it is facing? Heres my code.

var speed = 30.0;
var jumpSpeed = 15.0;
var gravity = 20.0;
var Lookspeed = 4.0;



private var moveDirection = Vector3.zero;
private var grounded : boolean = false;

function FixedUpdate() {
	if (grounded) {
		// We are grounded, so recalculate movedirection directly from axes
		moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
		moveDirection = transform.TransformDirection(moveDirection);
		moveDirection *= speed;
		
		if (Input.GetButton ("Jump")) {
			moveDirection.y = jumpSpeed;
		}
	}

	// Apply gravity
	moveDirection.y -= gravity * Time.deltaTime;
	
	// Look At Mouse
	var playerPlane = new Plane(Vector3.up, transform.position);
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hitdist = 0.0;
if (playerPlane.Raycast (ray, hitdist)) {
var targetPoint = ray.GetPoint(hitdist);
var targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Lookspeed * Time.deltaTime);
}
	var controller : CharacterController = GetComponent(CharacterController);
	var flags = controller.Move(moveDirection * Time.deltaTime);
	grounded = (flags  CollisionFlags.CollidedBelow) != 0;
		
}

@script RequireComponent(CharacterController)

Though there’s probably an elegant solution, I usually just embed the object in a container object.

Your mouse follow script would go on the inner object, and the keyboard movement script (was it a character controller?) would go on the outer object.

Don’t use transform.TransformDirection(moveDirection);

That is taking your World direction and transforming it relative to the current local transform.