Hi everyone,
I’ve been pulling my hair out for the last day trying to figure out why. I’ve got it to output the coordinates and the relative vector3 and they both look correct but the character just keeps walking past that point.
My code is largely unaltered from the example so I’m at a loss as to why the behaviour is misbehaving.
using System;
using UnityEngine;
using UnityStandardAssets.Characters.ThirdPerson;
[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:
break;
default:
return;
}
var playerToClickPoint = currentClickTarget - transform.position;
Debug.Log(playerToClickPoint);
if (playerToClickPoint.magnitude >= walkMoveStopRadius)
{
m_Character.Move(playerToClickPoint, false, false);
}
else
{
m_Character.Move(Vector3.zero,false,false);
}
}
}
}