Character movement issue

Hi
I found a simple Movement script.
I’ve added it to my Player’s Gameobject and It works good,but when the player is rotated in y axis and when I click the ‘W’ button,the Player is still going by x axis,but I want to make player follow by mouse while using ‘W,s,a’ and ‘d’ keys

Movement Script:

public float speed = 6.0F;
    public float jumpSpeed = 8.0F;
    public float gravity = 20.0F;
    private Vector3 moveDirection = Vector3.zero;

    void Update()
    {
        CharacterController controller = GetComponent<CharacterController>();
        // is the controller on the ground?
        if (controller.isGrounded)
        {
            //Feed moveDirection with input.
            moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
            moveDirection = transform.TransformDirection(moveDirection);
            //Multiply it by speed.
            moveDirection *= speed;
            //Jumping
            if (Input.GetButton("Jump"))
                moveDirection.y = jumpSpeed;

        }
        //Applying gravity to the controller
        moveDirection.y -= gravity * Time.deltaTime;
        //Making the character move
        controller.Move(moveDirection * Time.deltaTime);
    }

Hi Rlw

if you want make the player moving whenever your mouse are just put this code to your player

Move.cs :

using UnityEngine;
using System.Collections;

public class Move : MonoBehaviour {
	public float moveSpeed;
	void Start ()
	{
		moveSpeed = 1f;
	}
	
	void Update ()
	{
	 transform.Translate(Input.GetAxis("Mouse X")*Time.deltaTime,0f,Input.GetAxis("Mouse Y")*Time.deltaTime);
	}
}

and the LookArround.js :

#pragma strict
var x_rotation : float = 0.0; 
var y_rotation : float = 0.0;

var x_sensitivty : float = 5.0;
var y_sensitivty : float = 5.0;

function Update ()
{
	x_rotation += Input.GetAxis("Mouse X") * 5.0;
	y_rotation -= Input.GetAxis("Mouse Y") * 5.0;
	
	transform.localEulerAngles = Vector3 	(y_rotation, x_rotation, 0);
}

put them all to your character player and see what happen :slight_smile:

hope it will help you :smiley: