'How to fix move with wasd while using Cinemachine

PICTURE : https://i.stack.imgur.com/O9T5t.png

Hi, I just recently tried the tutorial of Roll A Ball in Unity. In the tutorial you only taught how camera follow the ball from 1 fixed point. But I want to edit so that the camera will always behind the ball to follow and they key WASD always the same. Its like openworld game such as GTA V, RDR2, etc..

I tried using Cinemachine for vcam and freelookcam, it works for the camera to follow but the key WASD messed up for example W should be for forward, but right now its moving backward.

Here is my PlayerController code for moving the player, I believe its on the OnMove function.

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

using UnityEngine.SceneManagement;

// Include the namespace required to use Unity UI and Input System
using UnityEngine.InputSystem;
using TMPro;

public class PlayerController : MonoBehaviour
{

    // Create public variables for player speed, and for the Text UI game objects
    public float speed;
    public TextMeshProUGUI countText;
    public GameObject winTextObject;

    private float movementX;
    private float movementY;

    private Rigidbody rb;
    private int count;

    // At the start of the game..
    void Start()
    {
        // Assign the Rigidbody component to our private rb variable
        rb = GetComponent<Rigidbody>();

        // Set the count to zero 
        count = 0;

        SetCountText();

        // Set the text property of the Win Text UI to an empty string, making the 'You Win' (game over message) blank
        winTextObject.SetActive(false);


    }

    void FixedUpdate()
    {
        // Create a Vector3 variable, and assign X and Z to feature the horizontal and vertical float variables above
        Vector3 movement = new Vector3(movementX, 0.0f, movementY);

        rb.AddForce(movement * speed);
    }

    void OnTriggerEnter(Collider other)
    {
        // ..and if the GameObject you intersect has the tag 'Pick Up' assigned to it..
        if (other.gameObject.CompareTag("PickUp"))
        {
            other.gameObject.SetActive(false);

            // Add one to the score variable 'count'
            count = count + 1;

            // Run the 'SetCountText()' function (see below)
            SetCountText();
        }
    }

    void OnMove(InputValue value)
    {
        Vector2 v = value.Get<Vector2>();

        movementX = v.x;
        movementY = v.y;
    }

    void SetCountText()
    {
        countText.text = "Count: " + count.ToString();

        if (count >= 12)
        {
            // Set the text value of your 'winText'
            winTextObject.SetActive(true);
            Time.timeScale = 0;




        }

    }





}



Solution 1:[1]

To solve this problem you have to adjust the input axis according to the camera.

Transform.TransformDirection("// input vector..");

With low corrections the problem may be solved.

void FixedUpdate()
{
    Vector3 movement = new Vector3(movementX, 0.0f, movementY);
    
    // affect base on camera direction
    movement = Camera.main.transform.TransformDirection(movement);

    movement.y = 0;

    rb.AddForce(movement.normalized * speed);
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 KiynL