Hello,
I started a test project and failed to properly implement a following enemy towards my character.
When I move my character my camera follows and the enemy is jittering when moving towards my character.
The Enemy’s movement is smooth when the camera is static.
Do you have any idea what’s causing this issue ?
Here’s the camera’s script
public class CameraController : MonoBehaviour
{
[SerializeField]
private Transform target;
[SerializeField]
private Vector3 offsetPosition;
[SerializeField]
private Space offsetPositionSpace = Space.Self;
[SerializeField]
private bool lookAt = true;
private void LateUpdate()
{
Refresh();
}
public void Refresh()
{
if (target == null)
{
Debug.LogWarning("Missing target ref !", this);
return;
}
// compute position
if (offsetPositionSpace == Space.Self)
{
transform.position = target.TransformPoint(offsetPosition);
}
else
{
transform.position = target.position + offsetPosition;
}
// compute rotation
if (lookAt)
{
transform.LookAt(target);
}
else
{
transform.rotation = target.rotation;
}
}
}
And the Enemy’s script :
public class enemyAi : MonoBehaviour
{
public Transform Target;
public UnityEngine.AI.NavMeshAgent agent;
// Start is called before the first frame update
void Start()
{
agent = gameObject.GetComponent<UnityEngine.AI.NavMeshAgent>();
}
// Update is called once per frame
void FixedUpdate()
{
agent.destination = Target.position;
}
}