Error while stop movement (on Click Mouse to move video)

Hello,

I did everything Ben did on PlayerMovement.cs, but I’m receiving the error you’ll watch in the video:

https://www.dropbox.com/s/04fj6izsy2oz2gm/VID_20170320_210903.mp4?dl=0

https://www.dropbox.com/s/04fj6izsy2oz2gm/VID_20170320_210903.mp4?dl=0

Seems like when the character is going to stop, it gets bugged.

This is the code:

[RequireComponent(typeof (ThirdPersonCharacter))]

public class PlayerMovement : MonoBehaviour
{
[SerializeField] float walkMoveStopRadius = 0.2f;

ThirdPersonCharacter m_Character;   // A reference to the ThirdPersonCharacter on the object
CameraRaycaster cameraRaycaster;
Vector3 currentClickTarget;
    
private void Start()
{
    cameraRaycaster = Camera.main.GetComponent<CameraRaycaster>();
    m_Character = GetComponent<ThirdPersonCharacter>();
    currentClickTarget = transform.position;
}

// Fixed update is called in sync with physics
private void FixedUpdate()
{
    if (Input.GetMouseButton(0))
    {
        print("Cursor raycast hit" + cameraRaycaster.hit.collider.gameObject.name.ToString());

		switch (cameraRaycaster.layerHit) 
		{
			case Layer.Walkable:
				currentClickTarget = cameraRaycaster.hit.point;  // So not set in default case
			break;

			case Layer.Enemy:
				print ("Enemy hit");
			break;

			default:
				print ("Unexpected layer found");
			return;
		}

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

}

}

Ok, sorry, I’ve found the solution. It was the - transform.position at the end, my bad ^^

1 Like

Privacy & Terms