- Home /
 
               Question by 
               Plecus · Oct 31, 2020 at 02:10 PM · 
                movementtransformcontrolleraxisdirections  
              
 
              Why does the player keep pointing in a specific direction after moving?
So for some reason, whenever the gameobject isn't moving, it starts to point in a specific direction, which is always a multiple of 90 degrees. I don't have much experience with Unity, and have no idea how this problem started. Does anyone here know how to fix this?
 private void Start()
 {
     controller = gameObject.AddComponent<CharacterController>();
     controller.skinWidth -= 0.0799f;
     controller.minMoveDistance -= 0.0009f;
 }
 void Update()
 {
     groundedPlayer = controller.isGrounded;
     if (groundedPlayer && playerVelocity.y < 0)
     {
         playerVelocity.y = 0f;
     }
     Vector3 move = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
     controller.Move(move * Time.deltaTime * playerSpeed);
     //Quatiernion rotation = Quaternion.LookRotation = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
     if (move != Vector3.zero)
     {
         gameObject.transform.forward = move;
     }
     // Changes the height position of the player..
     if (Input.GetButtonDown("Jump") && groundedPlayer)
     {
         playerVelocity.y += Mathf.Sqrt(jumpHeight * -3.0f * gravityValue);
     }
     playerVelocity.y += gravityValue * Time.deltaTime;
     controller.Move(playerVelocity * Time.deltaTime);
 }
               Comment
              
 
               
              You might want to add all the relevant code.
Secondly from what I could discern you are basically doing the below. Which instinctively feels a little convoluted.
So what are you actually trying to achieve?
 public class PlayerController : $$anonymous$$onoBehaviour
 {
     private CharacterController Controller { get; set; }
 
     private bool IsGrounded { get; set; }
 
     private float Speed { get; set; }
     
     private float JumpHeight { get; set; }
 
     private float Gravity { get; set; }
 
     void Start()
     {
         Controller = this.gameObject.GetComponent<CharacterController>();
         Controller.skinWidth -= 0.0799f;
         Controller.$$anonymous$$$$anonymous$$oveDistance -= 0.0009f;
     }
 
     void Update()
     {
         Controller.velocity.Set(
             Controller.velocity.x,
             Controller.isGrounded && Controller.velocity.y < 0 ? 0f : Controller.velocity.y,
             Controller.velocity.z
         );
 
         Vector3 move = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
 
         Controller.$$anonymous$$ove(move * Time.deltaTime * Speed);
 
         if (move != Vector3.zero)
         {
             gameObject.transform.forward = move;
         }
 
         // Changes the height position of the player..
         Controller.velocity.Set(
             Controller.velocity.x,
             Input.GetButtonDown("Jump") && IsGrounded ? Controller.velocity.y + $$anonymous$$athf.Sqrt(JumpHeight * -3.0f * Gravity) : Controller.velocity.y,
             Controller.velocity.z
         );
 
         Controller.velocity.Set(
             Controller.velocity.x,
             Controller.velocity.y + Gravity * Time.deltaTime,
             Controller.velocity.z
         );
 
         Controller.$$anonymous$$ove(Controller.velocity * Time.deltaTime);
     }
 }
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                