Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 Razputin · Aug 11, 2015 at 10:38 PM · inputcontrollersupportx-axisxboxcontroller

C# How to program X-Axis on Controller.

This is what I have right now, but I'm really not sure what it should actually look like, I can't find example code or anything like that anywhere.

  var h : float = Input.GetAxisRaw("Xbox_Joystick_X-Axis");
  var xPos : float = h * range;
  transform.position = new Vector3(xPos, 2f, 0);
  
  if(Input.GetKey("a") || Input.GetKey("left")||xPos < 0){
      if(rigidbody.velocity.x > 0){
          rigidbody.velocity.x = 0;
      }
      if(rigidbody.velocity.x > -walkSpeed){
          rigidbody.velocity.x -= 48*Time.deltaTime;
      }
  }
  //if the player pressed D, add velocity to move right.
  if(Input.GetKey("d")|| Input.GetKey("right")||xPos > 0){
      if(rigidbody.velocity.x < 0){
          rigidbody.velocity.x = 0;
      }
      if(rigidbody.velocity.x < walkSpeed){
          rigidbody.velocity.x += 48*Time.deltaTime;
      }
  }
 
Comment
Add comment · Show 12
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 Hexer · Aug 11, 2015 at 10:49 PM 0
Share

http://docs.unity3d.com/ScriptReference/Input.GetAxis.html

Unitys Reference page gives a pretty clear comment on how to do this. There is even a whole script provided by them. And there are actually tons of movement scripts on the web.

avatar image Razputin · Aug 11, 2015 at 11:18 PM 0
Share

I'm aware of the doc that's where I got the first part from. So that doesn't really help me.

avatar image Razputin · Aug 11, 2015 at 11:26 PM 0
Share

I know that. I'm asking what is wrong with my code. Is xpos not representing whatever the float is between -1 and 1

avatar image Hexer · Aug 11, 2015 at 11:36 PM 0
Share

I assume this script is in the function Update or FixedUpdate. + I dont know what walkSpeed means because there is no var that refers to it in your example.

avatar image Razputin · Aug 11, 2015 at 11:37 PM 0
Share

Update. And I am aware this script is shite. It was one of the earliest ones I did that's why I really need help fixing it lol.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

25 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

Related Questions

Unity ignoring joysticks of specified number 0 Answers

Unity Controller Support Help 0 Answers

Help Needed: How to Use Input Manager on UI Button 0 Answers

How do I standardize my game's input to different types of controllers? 1 Answer

How do you properly deal with analog joystick input on multiple controller inputs? 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