Modifying this move script to use local movement

What would be the easiest way to modify this script so that it uses movement relative to itself rather than relative to the world?

Here’s the script:

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

public class Movement : MonoBehaviour
{
    public float MoveSpeedMax;
    public float JumpSpeed;

    Vector3 PlayerVelocity;
    private Rigidbody RigidbodyComponent;

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

    // Use this for initialization
    void Start()
    {
        PlayerVelocity = Vector3.zero;
    }

    // Update is called once per frame
    void Update()
    {
        PlayerVelocity.z = Input.GetAxis("Vertical") * MoveSpeedMax;

        PlayerVelocity.x = Input.GetAxis("Horizontal") * MoveSpeedMax;

        if (Input.GetKeyDown(KeyCode.Space))
        {
            PlayerVelocity.y = JumpSpeed;
        }
        else
        {
            PlayerVelocity.y = RigidbodyComponent.velocity.y;
        }
   
        RigidbodyComponent.velocity = PlayerVelocity;
    }
}

Hi there,
I believe you are looking for Transform.TransformDirection .

I would write something like this:

var movementDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));

movementDirection = this.transform.TransformDirection(movementDirection);
PlayerVelocity = movementDirection * MoveSpeedMax;

[Edit] I think i got myself mixed up between InverseTransformDirection and TransformDirection, I’ve corrected the above.

Hope that helps.
Joe

That worked! The controls are really drifty because it keeps the momentum from other button presses, but I can probably fix that by adding drag etc.

Thank you for your help!

EDIT: nvm, I found a fix for the slidyness