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;
}
}