Help please. Im trying to get my player to rotate to the direction he is supposed to go to. It works for W and S but A and D does not rotate, yet still moves. How to solve this? please tell me, i actually have no idea.

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

public class NewPlayerController : MonoBehaviour {

    public float speed;
    public float jumpVelocity;
    public bool doubleJumpAvaible;
    public Animator anim;
    public bool isGrounded;
    public bool canMove;
    Rigidbody rb;



    void Start()
    {
        rb = GetComponent<Rigidbody>();
    }



    void Update()
    {

    }



    void FixedUpdate()
    {
        //Player movement
        if (canMove)
        {
            if (Input.GetKey(KeyCode.W))
            {
                transform.rotation = new Quaternion(transform.rotation.x, 0, transform.rotation.z, transform.rotation.w);
                transform.Translate(0, 0, speed * Time.deltaTime);
            }

            if (Input.GetKey(KeyCode.A))
            {
                transform.rotation = new Quaternion(transform.rotation.x, -90, transform.rotation.z, transform.rotation.w);                
                transform.Translate(0, 0, speed * Time.deltaTime);
            }

            if (Input.GetKey(KeyCode.D))
            {
                transform.rotation = new Quaternion(transform.rotation.x, 90, transform.rotation.z, transform.rotation.w);
                transform.Translate(0, 0, speed * Time.deltaTime);
            }

            if (Input.GetKey(KeyCode.S))
            {
                transform.rotation = new Quaternion(transform.rotation.x, -180, transform.rotation.z, transform.rotation.w);
                transform.Translate(0, 0, speed * Time.deltaTime);
            }
        }



    }





}

any help is appreciated.

If you’re going to set the values manually like that, you may as well just use euler angles and save yourself the headache of using quaternions.

  using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class NewPlayerController : MonoBehaviour {
  
      public float speed;
      public float jumpVelocity;
      public bool doubleJumpAvaible;
      public Animator anim;
      public bool isGrounded;
      public bool canMove;
      Rigidbody rb;
  
  
  
      void Start()
      {
          rb = GetComponent<Rigidbody>();
      }
   
  
      void FixedUpdate()
      {
          //Player movement
          if (canMove)
          {
              if (Input.GetKey(KeyCode.W))
              {
                  transform.eulerAngles = new Vector3(transform.eulerAngles.x, 0, transform.eulerAngles.z);
                  rb.velocity = speed * transform.forward);
              }
  
              if (Input.GetKey(KeyCode.A))
              {
                  transform.eulerAngles = new Vector3(transform.eulerAngles.x, -90, transform.eulerAngles.z);                
                  rb.velocity = speed * transform.forward);
              }
  
              if (Input.GetKey(KeyCode.D))
              {
                  transform.eulerAngles = new Vector3(transform.eulerAngles.x, 90, transform.eulerAngles.z); 
                 rb.velocity = speed * transform.forward);
              }
  
              if (Input.GetKey(KeyCode.S))
              {
                  transform.eulerAngles = new Vector3(transform.eulerAngles.x, 180, transform.eulerAngles.z); 
                  rb.velocity = speed * transform.forward);
              }
          }
  
  
  
      }
  
  
  
  
  
  }

I took the liberty of removing your update function as it shouldn’t be there if it isn’t doing anything. More importantly, I also switched your movement to be handled by giving your rigidbody velocity. You did well to handle the movement in FixedUpdate, but when moving a rigidbody you never want to move it by its transform. Doing so will prevent the physics engine from calculating proper collisions with it.

This should work well enough, but I’d suggest looking into lerping as a means of rotating the character to make the transition a bit more smooth. Good luck with your project!