Battlerite-like camera and movement

Hi there. I am new to gamedev stuff, just learning things, and I need some help with controls.

The idea is make my character move by WASD, and look at the cursor position. I done with camera, but can’t make it follow the cursor to the certain limit. Here’s a code:

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

public class Camera : MonoBehaviour
{
    //Variables
    public Transform player;
    public float smooth = 0.3f;

    public float height;

    private Vector3 velocity = Vector3.zero;


    //Methods
    void Update()
    {
        Vector3 pos = new Vector3();
        pos.x = player.position.x;
        pos.z = player.position.z - 7f;
        pos.y = player.position.y + height;
        transform.position = Vector3.SmoothDamp(transform.position, pos, ref velocity, smooth);
    }
}

The second one is make player moving. I got a script from tutorial, but the problem is cursor position affects my movement, here it is:

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

public class Player : MonoBehaviour
{
    //Variables
    public float movementSpeed;
    public GameObject camera;

    //Methods
    void Update()
    {
        //Player facing mouse
        Plane playerPlane = new Plane(Vector3.up, transform.position);
        Ray ray = UnityEngine.Camera.main.ScreenPointToRay(Input.mousePosition);
        float hitDist = 0.0f;

        if(playerPlane.Raycast(ray, out hitDist))
        {
            Vector3 targetPoint = ray.GetPoint(hitDist);
            Quaternion targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
            targetRotation.x = 0;
            targetRotation.z = 0;
            transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, 7f * Time.deltaTime);
        }


        //Player Movement
        if (Input.GetKey(KeyCode.W))
            transform.Translate(Vector3.forward * movementSpeed * Time.deltaTime);
        if (Input.GetKey(KeyCode.S))
            transform.Translate(Vector3.back * movementSpeed * Time.deltaTime);
        if (Input.GetKey(KeyCode.A))
            transform.Translate(Vector3.left * movementSpeed * Time.deltaTime);
        if (Input.GetKey(KeyCode.D))
            transform.Translate(Vector3.right * movementSpeed * Time.deltaTime);
    }

}

I never worked with programming, so it’s a kinda hard for me for now. Any help will be appreciated.

Hey I don’t know if your still having this problem but I’ll still give an answer to anyone looking.

    public float speed = 0f;
    int floorMask;
    float camRayLength = 100f;
  
 

    void Awake ()
    {
        floorMask = LayerMask.GetMask("Floor");
    }
 
    void FixedUpdate() {


        Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit floorHit;

        if (Physics.Raycast(camRay, out floorHit, camRayLength, floorMask))
        {
            Vector3 playerToMouse = floorHit.point - transform.position;
            playerToMouse.y = 0f;

            Quaternion newRotation = Quaternion.LookRotation(playerToMouse);
            transform.rotation = newRotation;
        }

        Vector3 playerRot = floorHit.point - transform.position;



     
        //movement based on the world axies

            //moves pos on z axis
            if (Input.GetKey(KeyCode.W))
            {
                transform.Translate(new Vector3(0f, 0f, speed * Time.deltaTime),Space.World);
         
            }
            //moves neg on z axis
            if (Input.GetKey(KeyCode.S))
            {
                transform.Translate(new Vector3(0f, 0f, -speed * Time.deltaTime), Space.World);

            }

            //moves pos on x axis
            if (Input.GetKey(KeyCode.D))
            {
                transform.Translate(new Vector3(speed * Time.deltaTime, 0f, 0f), Space.World);

            }

            //moves neg on x axis
            if (Input.GetKey(KeyCode.A))
            {
                transform.Translate(new Vector3(-speed * Time.deltaTime, 0f, 0f), Space.World);

            }

    }
}

The important part is in the transform.Translate we first put a vector then reference what we are translating based off of which, in this case is Space.World.
The translation is based on the world rather than the object being transformed. There is more info on this here.

There is no need for raycasting.

You need to have a position of your player and position of your cursor that’s all.
Cursor position - player position gives you direction vector so this is a point where your character should be looking.

You might use raycasting if you wish, but personally, I don’t like raycasting if it’s possible to avoid it.