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 /
avatar image
0
Question by Aldwoni_legacy · Jun 14, 2011 at 09:28 AM · inputjoystickgetaxis

joystick movement

I use a joystick to move around. When I don't touch my joystick, my character still moves. Is there a way to stop this?

 private var verticaal : float=0;
 private var horizontaal : float=0; 
 private var bewegingsgrenslinks :float;    
 private var bewegingsgrensrechts :float;    
 var script;    
 script = this.gameObject.GetComponent(speler);    
 bewegingsgrenslinks = script.bewegingsgrenslinks;    
 bewegingsgrensrechts = script.bewegingsgrensrechts;
 
 function Update(){  
     horizontaal = Input.GetAxis(script.horizontaal);
     verticaal = Input.GetAxis(script.verticaal);   
 if(transform.localPosition.y + verticaal <=-1)
 {
     verticaal = 0;
 }
 if( transform.localPosition.x + horizontaal <= bewegingsgrenslinks ||transform.localPosition.x +horizontaal >=bewegingsgrensrechts)
 {
     horizontaal = 0;
 }
     rigidbody.velocity = Vector3(horizontaal,verticaal,0);   
 }
Comment
Add comment · Show 5
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 aldonaletto · Jun 14, 2011 at 09:58 AM 0
Share

What does it mean: put my controller down?

avatar image Aldwoni_legacy · Jun 14, 2011 at 10:00 AM 0
Share

I don't know how to say it in english. but I mean when you don't touch your controller. is that better?

avatar image aldonaletto · Jun 14, 2011 at 10:07 AM 0
Share

Ok, you have a joystick or equivalent, and your character moves even when the joystick is in the null position, is it correct? Your character moves very slowly in this case? Are you using Input.GetAxis to read the joystick?

avatar image byerdelen · Jun 14, 2011 at 10:10 AM 0
Share

If you talk about input keys(keyboard) such as w,a,s,d. Then you are using Input feature such as Input.Get$$anonymous$$eyDown. But if you release the button, it still moves, then it is about how it is programmed, it shouldnt generally moves according to the tutorials of Unity and traditional program$$anonymous$$g as soon as it is a rigidbody with force, you need to show some code

avatar image Aldwoni_legacy · Jun 14, 2011 at 10:13 AM 0
Share

I use Input.GetAxis on my joystick

2 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by aldonaletto · Jun 14, 2011 at 11:07 AM

Input.GetAxis can return small values when the joystick (or other game controller) is slightly uncalibrated. Due to this, you should never compare Input.GetAxis to zero, like this:

   if (Input.GetAxis("Vertical")>0){
     // moves the character forward with velocity maxSpeed

Since Input.GetAxis returns a float value between -1 and 1, the best approach is to use something like this:

   var dz = Input.GetAxis("Vertical");
   if (Mathf.Abs(dz)>0.01){
     // move the character forward with velocity dz * maxSpeed

The value returned by GetAxis is compared to a "safety margin", so small values will not move the character. If this doesn't solve your problem, please post the script where you read the game controller.

Comment
Add comment · Show 9 · 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 Aldwoni_legacy · Jun 14, 2011 at 12:13 PM 0
Share

I used the Input $$anonymous$$anager of unity and set the Dead to 0.1, but it doesn't work as expected.

avatar image aldonaletto · Jun 14, 2011 at 12:34 PM 0
Share

Post the script where you read Input.GetAxis and move your character.

avatar image aldonaletto · Jun 14, 2011 at 02:01 PM 0
Share

1- There's something wrong with the line below:

if(transform.localPosition.y + verticaal =bewegingsgrensrechts)

Is the = supposed to be >= or ?
2- You can avoid leakage values doing the following check:

if ($$anonymous$$athf.Abs(horizontaal)<0.01) horizontaal = 0;
if ($$anonymous$$athf.Abs(verticaal)<0.01) verticaal = 0;

3- The rigidbody will keep its velocity until friction consumes it; set the Drag rigidbody parameter to 0.5 or something alike to stop the object after a decent time.

avatar image Aldwoni_legacy · Jun 14, 2011 at 02:17 PM 0
Share
  1. solved, some of my good went missing with copy pasting. tested 2 and 3 but didn't fixed the problem.

avatar image aldonaletto · Jun 14, 2011 at 05:09 PM 0
Share

Well, let's go back to the beggining:
1- When do you character start to move alone? As soon as the game starts? Or only after you move it with the joystick?
2- When the joystick is at null position, how does the character keep moving? Very slowly or at normal speed?

Show more comments
avatar image
1

Answer by tnetennba · Jun 14, 2011 at 11:09 AM

It is likely that you are not setting a dead zone on your controller. What you need to do is set a small area on the stick that does not respond to any input.

To do this when you do Input.GetAxis you need to do something like:

             float ax = Input.GetAxis("Mouse X");
         if( ax < 0.1f  && ax > -0.1f)
         {
             ax = 0.0f;
         }

You now have a dead zone between -0.1 and 0.1 on that particular axis. This issue is caused due to controller stick not sitting exactly at 0.0 even when noone is using them.

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 Aldwoni_legacy · Jun 14, 2011 at 12:13 PM 0
Share

I used the Input $$anonymous$$anager of unity and set the Dead to 0.1, but it doesn't work as expected.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Input.GetAxis returning nonsensical values for HID Sensor/GameController 0 Answers

Joystick input Problem 3 Answers

Map mobile joystick to Input.GetAxis("Horizontal") and "Vertical" 1 Answer

Get DPad input value via GetButton instead of GetAxis? 8 Answers

Steering Wheel / joystick GetAxis trouble 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