Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by 12toe · May 09, 2020 at 06:49 PM · keyboardgetaxis

What can affect Input.GetAxis after building?

Hey there! I've built and run an early version of my game, and it works great using my wireless keyboard. I've tested it on other computers with different keyboards, and it works with them too.

I sent it to my friend, and almost everything works as intended except for one major thing, the player character refuses to move based on the Input.GetAxisRaw function. What's weird is that I have a child Empty GameObject attached to the player that plays footstep noises when the player presses a direction IS playing.

So the footsteps recognize the input, but the player movement script doesn't. What's up with that? Can a monitor's refresh rate affect the GetAxisRaw function? I've been testing on a 60hz monitor, where my friend is using a 165hz monitor. That's like the only thing I can think of that could affect the input.

If anyone has any insight or advice, that'd be much appreciated!

EDIT #2: Here's my movement script:

 void Update() {
         //input
         Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
         Vector2 inputDir = input.normalized;
         bool running = Input.GetKey(KeyCode.LeftShift);
 
         Move(inputDir, running);
 
 }
 
 void Move(Vector3 input, bool running) {
      if (inputDir != Vector2.zero) //if input direction returns a value that isn't (0,0)
         {
             float targetRotation = Mathf.Atan2(inputDir.x, inputDir.y) * Mathf.Rad2Deg + cameraT.eulerAngles.y; // set target rotation towards input direction (x,y), find the angles relative to the camera
             transform.eulerAngles = Vector3.up * Mathf.SmoothDampAngle(transform.eulerAngles.y, targetRotation, ref turnSmoothVelocity, GetModifiedSmoothTime(turnSmoothTime)); // rotate player object smoothly
 
         }
 
 
         float targetSpeed = ((running) & haveStamina ? runSpeed : walkSpeed) * inputDir.magnitude; //if running = true, set target speed to runspeed. Otherwise set target speed to walkspeed * inputdirection
         currentSpeed = Mathf.SmoothDamp(currentSpeed, targetSpeed, ref speedSmoothVelocity, GetModifiedSmoothTime(speedSmoothTime)); //smoothly ease our current speed into the target speed
         
 
         velocityY += Time.deltaTime * gravity; //vertical velocity is equal to the value of gravity multiplied by time
         Vector3 velocity = transform.forward * currentSpeed + Vector3.up * velocityY; 
 
         controller.Move(velocity * Time.deltaTime);
         currentSpeed = new Vector2(controller.velocity.x, controller.velocity.z).magnitude;
 }

And here's the footstep sound empty object :

 void Update() {
 GetState();
 PlayAudio();
 }
 
 void GetState()
     {
         Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
         Vector2 inputDir = input.normalized;
 if (inputDir != Vector2.zero)
         {
 
 
             if (Input.GetKey("left shift") && !overheated)
             {
                 audioPlayer.pitch = 1.3f;
                 isRunning = true;
 
             }
             else
             {
                 isRunning = true;
                 audioPlayer.pitch = 1f;
             }
         }
         else
         {
             isRunning = false;
             audioPlayer.pitch = 1f;
         }
 }


Also something else that came up was that my attempts to limit the application framerate to 30 failed with my friend's monitor. Apparently

     void Awake()
     {
 
         QualitySettings.vSyncCount = 2;
         Application.targetFrameRate = 30;
 
     }

Doesn't work either. I'm so confused with why certain monitors can affect performance? Especially when I'm limiting the framerate.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by FlaSh-G · May 10, 2020 at 04:31 AM

The results of GetAxis shouldn't ever change, but the code you have written around calling that method might not respond well to the changed framerate.

What's wrong with this code is impossible to guess without seeing it. Either way, try a development build and output some stuff! Or, maybe even better, try to reproduce the bug on a machine with that framerate output, but within the editor.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image 12toe · May 10, 2020 at 07:39 AM 0
Share

Thanks for the response! I'll definitely make a dev build to see what's going on. As well as post some code to add clarity!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

127 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Get smooth input when Time.timescale == 0 1 Answer

How to get the "Command" hold down on Mac OS? 1 Answer

unbuffered keyboard input delay 2 Answers

How to use event.KeyCode 1 Answer

In the game does not work the keyboard on the Russian version of mac os x lion 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges