- Home /
 
               Question by 
               calender68 · Apr 24, 2019 at 05:01 AM · 
                movementmovement scriptplayer movementthird-personthird person controller  
              
 
              How to disable A, S, and D keys for third person player movement
Hello! I'm new to scripting and I have a quick question. On my third person game, I don't want players moving left/right or down. They can only move forward while using the mouse to change directions. The script I have now uses WASD keys to move. How do I make it so that the A, S, and D keys don't do anything when pressed? I searched all over for the answer but can't seem to find anyone who has this scenario. Here it my player movement script:
     private void CheckInput()
     {
         float vertical = Input.GetAxis("Vertical");
         float horizontal = Input.GetAxis("Horizontal");
         float horizontalrotation = (Input.GetAxis("Mouse X") * Time.deltaTime * 100);
         float rotateSpeed = 28f;
         transform.position += transform.forward * (vertical * moveSpeed * Time.deltaTime);
         transform.position += transform.right * (horizontal * moveSpeed * Time.deltaTime);
         transform.Rotate(new Vector3(0, horizontalrotation * rotateSpeed * Time.deltaTime, 0));
               Comment
              
 
               
               private void CheckInput()
 {
     if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.W)) { //to execute this only pressed W
          float vertical = Input.GetAxis("Vertical");
          float horizontalrotation = (Input.GetAxis("$$anonymous$$ouse X") * Time.deltaTime * 100);
          float rotateSpeed = 28f; //You could define this globally ins$$anonymous$$d
          transform.position += transform.forward * (vertical * moveSpeed * Time.deltaTime);
     } 
 }
 
               Best Answer 
              
 
              Answer by Hellium · Apr 24, 2019 at 06:59 AM
  private void CheckInput()
  {
      float vertical = Mathf.Max( Input.GetAxis("Vertical"), 0 );
      float horizontalrotation = (Input.GetAxis("Mouse X") * Time.deltaTime * 100);
      float rotateSpeed = 28f;
      transform.position += transform.forward * (vertical * moveSpeed * Time.deltaTime);
      transform.Rotate(new Vector3(0, horizontalrotation * rotateSpeed * Time.deltaTime, 0));
 }
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                