Hello forum, I’m trying to learn about pathfinding and I have a wall and a capsule, the capsule is supposed to walk to the target capsule upon LookAt(Target) but the capsule isn’t moving. I’m not sure why it’s not working, the code looks correct as I’m following from a tutorial online. I’m getting object reference not set to an instance of an object error in unity, Target is set up with the capsules rigidbody. Here is my code -
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AIAgent : MonoBehaviour
{
public float Speed = 5;
public Transform Target;
Rigidbody rb;
// Start is called before the first frame update
void Awake()
{
rb.GetComponent<Rigidbody>();
}
// Update is called once per frame
void FixedUpdate()
{
rb.MovePosition(rb.position + (transform.forward * Time.deltaTime * Speed));
transform.LookAt(Target);
}
void OnDrawGizmos()
{
Gizmos.color = Color.red;
Gizmos.DrawLine(transform.position, transform.position+(transform.forward*5));
}
}
Advice please, thank you.
