Forum Thread
  Posts  
Help on player movement (2D topdown) (Forums : Tech Support : Help on player movement (2D topdown)) Locked
Thread Options
Apr 12 2020 Anchor

Hi everyone this is my first post.


I'm developing a 2D topdown mmo on unity for fun and right now the player movement (mouse movement with pathfinding) is somewhat done. The thing is that it does not feel smooth at all and I want it to be as smooth as possible. Every time the mouse click is press to move the player, the player stutters.

crusaderWalk5

Here is the player movement script.

if(Input.GetKeyDown(KeyCode.Y)){
            ToggleCamera();
        }

        if(Input.GetKeyDown(KeyCode.Mouse1)){
            if(clickHandler.ValidClick()){
                if (clickedTile(MousePos(), currentFloorLevel) == null)
                {
                    mousePos = MousePos();
                    Path = EventManager.RaiseOnClickMove(mousePos, transform.position, layermask);
                    if (Path != null)
                    {
                        mov = Path[0].Position;
                        //TurnPlayer(mov);
                    }
                }
            }
        }

        if(Path != null && Path.Count > 0){
            if(transform.position == mov){
                Path.RemoveAt(0);
                if(Path.Count > 0){
                    mov = Path[0].Position;
                    moving = true;
                }
            }else if(!AStar.Obstruction(transform.position, Path[0].Position, layermask)){
                moving = true;
                MovePlayer(mov,movSpeed);

            }else{
                Path = EventManager.RaiseOnClickMove(mousePos, transform.position, layermask);
                if (Path != null){
                    mov = Path[0].Position;
                    //TurnPlayer(mov);
                }
            }      
        }
        else
        {
            moving = false;
        }
        anim.SetBool("Walking", moving);

At first I thought the problem was the animation but it doesn't seem like it since the animation keeps cycling correctly.

Reply to thread
click to sign in and post

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.