Whenever I try adding force to an object, it gives me the following error: error CS1061: 'Rigidbody' does not contain a definition for 'AddForce' and no accessible extension method 'AddForce'

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    private float horizontal;
    private float vertical;
    public Rigidbody rb;
    public Vector3 direction;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        horizontal = Input.GetAxisRaw("Horizontal");
        vertical = Input.GetAxisRaw("Vertical");
        direction = transform.forward * vertical + transform.right * horizontal;
    }
    void FixedUpdate(){

    }
    void MovePlayer(){
        rb.AddForce(direction * 8f, ForceMode.Force);
    }
}

At the moment, I don’t see how your code would run. MovePlayer is not called by anything…

A couple of topics:

You have made rb public so you must drag the RigidBody component into the appropriate field in the Inspector.

It’s better not to declare the rb as public and drag the field in. (Likewise direction should be private) Making something public when not needed exposes a variable to other code and that’s not good. Instead, make it private and add an Awake() event like this:

void Awake()
{
    rb = GetComponent<Rigidbody>();
}

That way, you don’t forget to drag in the component.

You’ve created what we call a direction vector but we usually normalize these, meaning the magnitude is the same vertically, horizontally and diagonally.

Finally, AddForce. in FixedUpdate. My simplified version of your code looks like this:

using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    Rigidbody rb;
    Vector3 direction;

    void Awake()
    {
        rb = GetComponent<Rigidbody>();
    }

    void Update()
    {
        float horizontal = Input.GetAxisRaw("Horizontal");
        float vertical = Input.GetAxisRaw("Vertical");
        direction = (transform.forward * vertical + transform.right * horizontal).normalized;
    }

    void FixedUpdate()
    {
        rb.AddForce(direction * 50f, ForceMode.Force);
    }
}