Character will not stop moving

Ok so my character follows the mouse cursor and dose not stop. I’m not sure in what script i might have a problem in. I’m thinking its in the Player Movement.
PlayerMovement.zip (778 Bytes)

Hi Michael,

I have compared your code to that of the course in the GitHub respository for the relevant section;

You have;

        var playerToClickPoint = currentClickTarget - transform.position;
        if (playerToClickPoint.magnitude >= walkMoveStopRadius)
        {
            m_Character.Move(cameraRaycaster.hit.point - transform.position, false, false);
        }
       else 
        {
            m_Character.Move(Vector3.zero, false, false);
        }

the course has;

         var playerToClickPoint = currentClickTarget - transform.position;
         if (playerToClickPoint.magnitude >= walkMoveStopRadius)
         {
             m_Character.Move(playerToClickPoint, false, false);
         }
         else
         {
             m_Character.Move(Vector3.zero, false, false);
         }

The issue, I believe, is in that first line of the if statement. In the course code, it is using the playerToClickPoint variable, this is set based on the currentClickTarget which, itself, is only set within the if statement which detected for the mouse button being pressed.

In your version, you are using the raycase hit point, as such, it is using where-ever the mouse is now, and ignores what has been set in the two preceding variables.

Hope this helps :slight_smile:

Just for reference, it is typically easier for everyone if you copy/paste your code directly into your posts and then apply the code formatting characters both before and after it to format it nicely. Sometimes you may find you don’t get responses as having to download a file, check it for viruses, open it up and finally review it can be a put off for some people.


See also;

Thank you :slight_smile:

1 Like

You’re welcome Michael.

Is it working as expected now?

Yes it is.

1 Like

Great, glad you can move on again now (excuse the pun, couldn’t resist :wink: )

Moving on was not the problem he would not stop lo :laughing:

1 Like

:rofl:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms