Problem with transforming rotation (noob question)

Hey, I’m working on my first Unity project and ran into an issue setting up movement controls for my 3D player character. I’m very new to programming and C# alike, so I used a tutorial to do this and (aside from renaming the variables) followed it to a T. Everything works as intended, except for the movement direction of the character. The movement direction remains the same regardless of the way the camera is facing, in what I assume are the default angles of the world. In other words, when I press “W” the character always moves in the reverse direction of where he was initially facing, even if I’m looking elsewhere. No one in the comments of the tutorial video mentioned this issue, and in the tutorial itself the movement directions worked fine. As such, I tried several other tutorials and googling as well as some clueless attempts of my own, but the same issue remained. If I understand the code correctly, I assume the problem is that “transform” isn’t picking up the rotation of the character object. The current, cobbled-together version of the script is as follows:

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

public class Charmove : MonoBehaviour
{
    CharacterController characterController;

    public float speed = 6.0f;
    public float jumpSpeed = 8.0f;
    public float gravity = 20.0f;
    private Cameralook cameraLook;
    public Transform cam;

    private Vector3 moveDirection = Vector3.zero;

    void Start()
    {
        characterController = GetComponent<CharacterController>();
        cameraLook = GetComponent<Cameralook>();
    }

    void Update()
    {
        MovePlayer();
    }
    private void MovePlayer()
    {
        float horInput = Input.GetAxis("Horizontal") * speed;
        float verInput = Input.GetAxis("Vertical") * speed;
        Vector3 camF = cam.forward;
        Vector3 camR = cam.right;
        camF.y = 0;
        camR.y = 0;
        camF = camF.normalized;
        camR = camR.normalized;
        transform.position += (camF * verInput + camR * horInput);
        if (characterController.isGrounded)
        {
            if (Input.GetButton("Jump"))
            {
                moveDirection.y = jumpSpeed;
            }
        }
        moveDirection.y -= gravity * Time.deltaTime;
    }
}

The object I’m using for the player character is a Blender model, in case that matters at all. It’s well possible I’ve messed something up on Blender’s end too, since I’m new to that as well. I’ll provide more info if necessary, just not sure what to include and what not to right now. Thanks in advance for any help, I’m personally at my wits’ end.

Lines 31 and 32 should be taking care of this, but they do depend on what is assigned to the “cam” variable in the inspector. Is that reference correctly assigned?

It’s a public Transform, if you mean something else by assigning it’s probably something I don’t know about. I’ve tried transform.forward, Camera.main.transform.forward (the camera is parented to the character) and something with getComponent from the script defining the camera angle in it’s place as well. Same problem with all of them

I mean, look at your object in the Inspector in Unity. You should see a “Cam” variable, and some object assigned to in in it (much like the “Cam” variable in this screenshot)

Ah, I see… the “Cam” variable isn’t actually showing up in unity, what could be causing that? The other variables (speed, jump speed, gravity) are all there.

That’s odd, it should be. Do you have any compile errors in your console?

None; I tried adding different variables to the script, and none of them show up in unity beyond those first three. In the other script, for the camera angle, I can add new variables and they show up fine. I tried copying the script to a new file, and none of the variables show up now. Not sure what’s going on.

Well, I got it fixed… sort of. I renamed the new script file and class, and suddenly all the variables appeared. I assigned the object to “Cam”, and the directions got fixed. Also, gravity stopped working and the speed multiplied by around ten for some reason, but that’s probably solvable. Thanks a lot for the help!