Rotation

Hello, here I go again with another problem… :z

Now I’m testing 3D games, and the thing is: I want my player to look at where my “RIGHT STICK” value is.

using System;
using System.Numerics;
using UnityEngine;
using UnityEngine.InputSystem;
using Quaternion = UnityEngine.Quaternion;
using Vector3 = UnityEngine.Vector3;
//ReSharper Disable All

public class Player : MonoBehaviour
{
    //Cria o controle do jogador.
    public CharacterController controller;

    //Cria a velocidade, gravidade e altura máxima de pulo.
    public float speed;
    public float speedMult;
    public float gravity = -9.81f;
    public float rotationSpeed;

    //Cria o detector de colisão, a distancia que o detector irá detectar e a máscara para sinalizar o objeto que irá ter o detector.
    public Transform groundCheck;
    public float groundDistance = 0.4f;
    public LayerMask groundMask;

    //Cria uma velocidade baseada no Vector3 e uma boleana para ver se o Player está no chão, se sim, ele pode pular ao contrário sem pulo.
    Vector3 velocity;
    bool isGrounded;

    void Update()
    {
        //Cria uma esfera em baixo do jogador que checará a colisão dele com o chão.
        isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);

        //Se há gamepad.
        var gamepad = Gamepad.current;
        if (gamepad == null)
            return;

        //Faz com que o jogador não fique indo para baixo, aumentando infinitamente seu y.
        if (isGrounded && velocity.y < 0)
        {
            velocity.y = -2f;
        }

        //Cria variáveis de movimento.
        var x = gamepad.leftStick.x.ReadValue();
        var z = gamepad.leftStick.y.ReadValue();

        Vector3 move = transform.right * x + transform.forward * z;

        //Faz o jogador se movimentar pelo componente Character Controller.
        controller.Move(move * speed * Time.deltaTime);

        //Faz o jogador ter gravidade.
        velocity.y += gravity * Time.deltaTime;

        //Faz a gravidade ser usada.
        controller.Move(velocity * Time.deltaTime);

        var xLook = gamepad.rightStick.x.ReadValue();
        var yLook = gamepad.rightStick.y.ReadValue();

    }
}

I’ve tested several thins using Quaternion, Rotate and transform.rotation but it’s 2 days and I haven’t find a solution yetm anyone have any ideias?

If I understand what you’re asking for then you want to set your characters rotation with

Vector3 direction = new Vector3(rightStick.x, 0, rightStick.y); //if y axis is up
character.transform.rotation = Quaternion.LookRotation(direction);

Hope this helps!