Is there an easier way of doing this?

I am new to programming and am following a Tutorial so this code is not perfect. I wanted to expand on the movement to make it more interactive and fun but wonder if there is a more effective or better way of doing the movement?
I have 2 Scripts one to rotate the camera around the Focal Point with the mouse on the x Axis.

using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class RotateCamera : MonoBehaviour
{
    [SerializeField] private float rotationSpeed = 20.0f;
    [SerializeField] private float mouseSense = 1.00f;

    // Start is called before the first frame update
    void Awake()
    {
        Cursor.lockState = CursorLockMode.Locked;
    }

    // Update is called once per frame
    void Update()
    {
        Rotate();
    }

    public void Rotate()
    {
        float horizontalInput = Input.GetAxis("Mouse X");
        transform.Rotate(Vector3.up, horizontalInput * rotationSpeed * mouseSense * Time.deltaTime);
    }
}

And then there is this script

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

public class PlayerController : MonoBehaviour
{
    [SerializeField] private float playerSpeed;
    private Rigidbody playerRB;
    private GameObject focalPoint;

    // Start is called before the first frame update
    void Start()
    {
        // playerRB gets the Rigigbody Component from the Player GameObject
        playerRB = GetComponentInChildren<Rigidbody>();
        focalPoint = GameObject.Find("Focal Point");
    }

    // Update is called once per frame
    void Update()
    {
        // Get Inputs
        float horizontalInput = Input.GetAxis("Horizontal");
        float verticalInput = Input.GetAxis("Vertical");
        
        // Move Player
        playerRB.AddForce(focalPoint.transform.forward * verticalInput * playerSpeed);
        playerRB.AddForce(focalPoint.transform.right * horizontalInput * playerSpeed);
    }
}

Yes, there’s always different ways that are better or worse suited.

Meanwhile, if it works, move on. Seriously.

NOTE: if you don’t understand 100% of what you are doing, go back and fix that first. Otherwise you’re not actually the author of your game. :slight_smile:

Two steps to tutorials and / or example code:

  1. do them perfectly, to the letter (zero typos, including punctuation and capitalization)
  2. stop and understand each step to understand what is going on.

If you go past anything that you don’t understand, then you’re just mimicking what you saw without actually learning, essentially wasting your own time. It’s only two steps. Don’t skip either step.