Character Controller base code help! (3d and c#)

I’ve been working on a player controller and I just can’t seem to get the basics of the controller right. All of the tutorials out there are messy with features that I neither need nor want. Can someone please provide me with code for a controller that I can copy/paste into visual studio that does only these basic things:

  1. Move character forwards, backwards, left and right.
  2. Moves character in direction based on camera orientation.
  3. Rotates character towards direction they are (or were) moving in.
    To be clear, I won’t just copy your work. I just really need something basic to look at and figure out. I really want to learn but no matter how much I try I keep coming back to this same issue. I know this is probably something really easy to code but it would mean soooo much to me by giving me something clean and basic to learn and jump off from.

here is my code. Please read through my comments and if you don’t understand something, or it’s causing problems please speak up. I’m always happy to help

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

public class MyCharacterController : MonoBehaviour
{
    GameObject mainCamera;

    //used to make smooth transitions in the rotation - greater values = less time
    public float rotationDamping = 6;

    //used to smooth the movement and get rid of laggy characteristics - greater values = less time
    public float movementDamping = 2;

    //how fast are you moving? - greater values = faster character
    public float movementSpeed = 5;


    // Start is called before the first frame update
    void Start()
    {
        //get a reference to the main camera
        mainCamera = Camera.main.gameObject;
    }


    // Update is called once per frame
    void Update()
    {
        //get our direction from these default axis
        Vector3 direction = new Vector3(Input.GetAxisRaw("Horizontal"), 0f, Input.GetAxisRaw("Vertical"));

        //if the camera is pointing straight down, you encounter some issues with the player moveing straight down.
        if(mainCamera.transform.eulerAngles.x == 90 || mainCamera.transform.eulerAngles.x == -270) 
        {
            //***take our direct compared to the mainCamera***
            direction = mainCamera.transform.TransformDirection(direction);
            //camera rotation solution
            direction.z = -direction.y;
            direction.y = 0;
            //calculate what we wish to add to our position
            Vector3 addPos = Vector3.Normalize(direction)*movementSpeed;

            //***move***
            //here we lerp between our positions for a smooth transition
            float posX = Mathf.Lerp(transform.position.x, transform.position.x + addPos.x, movementDamping * Time.deltaTime);
            float posY = Mathf.Lerp(transform.position.y, transform.position.y + addPos.y, movementDamping * Time.deltaTime);
            float posZ = Mathf.Lerp(transform.position.z, transform.position.z + addPos.z, movementDamping * Time.deltaTime);
            //now we set our position
            transform.position = new Vector3(posX,posY,posZ);

            //***look in the direction we are moving***
            Quaternion oldAngles = transform.rotation;
            //look at were we are going to be
            transform.LookAt(new Vector3(addPos.x+transform.position.x, transform.position.y, addPos.z+transform.position.z));
            //smooth that transition out
            transform.rotation = Quaternion.Slerp(oldAngles, transform.rotation, Time.deltaTime * rotationDamping);
        }
        else
        {
            //***take our direct compared to the mainCamera***
            direction = mainCamera.transform.TransformDirection(direction)*movementSpeed;
            direction.y = 0.0f;
 
            //calculate what we wish to add to our position
            Vector3 addPos = Vector3.Normalize(direction)*movementSpeed;

            //***move***
            //here we lerp between our positions for a smooth transition
            float posX = Mathf.Lerp(transform.position.x, transform.position.x + addPos.x, movementDamping * Time.deltaTime);
            float posY = Mathf.Lerp(transform.position.y, transform.position.y + addPos.y, movementDamping * Time.deltaTime);
            float posZ = Mathf.Lerp(transform.position.z, transform.position.z + addPos.z, movementDamping * Time.deltaTime);
            //now we set our position
            transform.position = new Vector3(posX,posY,posZ);

            //***look in the direction we are moving***
            Quaternion oldAngles = transform.rotation;
            //look at were we are going to be
            transform.LookAt(new Vector3(addPos.x+transform.position.x, transform.position.y, addPos.z+transform.position.z));
            //smooth that transition out
            transform.rotation = Quaternion.Slerp(oldAngles, transform.rotation, Time.deltaTime * rotationDamping);
        }
    }
}

*create a script called “MyCharacterController”

*copy paste

*put script onto your character

*play and change to fit your needs

@JxWolfe Do you want to exchange discords or something? This means so much to me and I want to repay the favor somehow. If you’re ever interested in 3d modeling, animation, or digital art hit me up!