Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
This question was closed Nov 18, 2015 at 04:07 PM by Razputin.
avatar image
0
Question by Razputin · Nov 18, 2015 at 03:26 AM · 2dmovementcontrollerplatformersupport

Moving using controller stick question

Trying to make it so -1 on the axis moves the player left and 1 moves the player right but my script doesnt appear to do anything. I was never able to figure out how to properly do controller support for my last game but I really want to include it this time because people seemed to really want it. I can do the buttons easy enough but I don't understand the axis's. What am I doing wrong?

             if(Input.GetButton("Horizontal"))
             {
                 if(Input.GetAxisRaw("Horizontal") < 0)
                 {
                     Debug.Log("Left");
                     vel.x = -walkSpeed;
                 }
                 if(Input.GetAxisRaw("Horizontal") > 0)
                 {
                     Debug.Log("Right");
                     vel.x = walkSpeed;
                 }
             }else
             {
                 vel.x = 0;
             }
 
         

My project settings for "Horizontal" Are currently the default ones found when creating a new project in unity.

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

  • Sort: 
avatar image
0

Answer by ian_sorbello · Nov 18, 2015 at 03:46 AM

This would be simpler:

 vel.x = Input.GetAxis("Horizontal");
 if(vel.x != 0)
     vel.x = (vel.x < 0) ? -walkspeed : walkspeed

This assumes that the "Horizontal" axis is registered in Unity (Edit->Project Settings->Input), and of course that the result (vel.x) actually does something to your object

Comment
Add comment · Show 4 · 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 Razputin · Nov 18, 2015 at 03:52 AM 0
Share

Still doesn't do anything.

$$anonymous$$aybe my project settings are wrong?

Name : Horizontal Neg Button: Left Pos Button: Right Alt Neg: A Alt Pos: D Grav: 3 Dead: 0.001 Sens : 3 Snap : Yes Invert : No Type : $$anonymous$$ey or $$anonymous$$ouse Button Axis : x axis Joy Num : Get $$anonymous$$otion From all

avatar image MCoburn Razputin · Nov 18, 2015 at 04:39 AM 0
Share

You need to add another axis registered in the input manager for the joystick.... I think.

If in doubt, bring your movement script over to a clean fresh project and see if that works, then if it does, you know the inputs got mangled up somehow.

avatar image Razputin MCoburn · Nov 18, 2015 at 04:42 AM 0
Share

Can you expand on that? I don't usually muck about with inputs. What settings would I apply to the new input.

avatar image Razputin · Nov 18, 2015 at 08:08 AM 0
Share

Bumping because I'd really like to know whats wrong :(

Follow this Question

Answers Answers and Comments

44 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Damaging Enemies 1 Answer

sprite character rotation 0 Answers

Are Character Controllers inefficient? 1 Answer

How to switch animation controllers dynamically? 1 Answer


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