Player move and camera problem

Hi everyone, I’ve started to use Unity3D one week ago… I’ve done a lot of trials before ask this… I’ve change code a lot of times… I’ve been able to solve some errors… But i didn’t understand where is this bug… It works fine at start but when you move some mouse and keyboard, it gives some problems… This JavaScript have to be applicated to a Player (Capsule) with behind a Main Camera (used this to semplify work)… So if someone can help me, A lot of thanks!!!


private var direction : Vector3; // Direction of player to know next position
function Update () {
    Camera.main.transform.LookAt(transform); // Normal LookAt function
    direction = Camera.main.transform.forward; // I've set the direction of player like camera's one.
    transform.Translate(direction * Input.GetAxis("Vertical"),Space.World); // Up/Down move player near/further than camera
    transform.Translate(direction.z * Input.GetAxis("Horizontal"),0,direction.x * -Input.GetAxis("Horizontal"),Space.World); // Horizontal Movement
    var mouX : float = Input.GetAxis("Mouse X");
    var mouY : float = Input.GetAxis("Mouse Y");
    transform.RotateAround(transform.position,Vector3.up,mouX); // Move Player and camera horizontally by mouse
    var euler = Camera.main.transform.eulerAngles.x; // See camera's rotation to put a limit
    if(euler < 180){
        if((euler < 50) || (mouY > 0)) // I don't want a lot of vertical vision
            Camera.main.transform.RotateAround(transform.position,Vector3.right,-mouY); // To look Around
        if((euler > 330) || (mouY < 0))
    Screen.lockCursor = true; // Normal Cursor locked function

Vector3.right will always rotate around the world X axis. Once you rotate your character around Y, this is no longer what you want.

So instead, rotate around the local X axis of your character:


Note on the other hand, the use of Vector3.up is generally fine, since you usually still want to rotate around world Y instead of local Y, even if your character is facing up or down.

when player moves grass on terrain removed after some distance and no grass seen on terrain after some distance pls help to sovle it???