Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 RealMTG · Apr 06, 2015 at 01:35 PM · axisfixedupdatevertical

Using Vertical axis in 2D only moves object by 0.1

Hi

I am having some problems with my ship controller. I have want it to move up, down, left and right but when I try to move up or down it only moves by 0.1. Here's my script.

 void FixedUpdate()
     {
         float moveHorizontal = Input.GetAxis("Horizontal");
         float moveVertical = Input.GetAxis("Vertical");
 
         Vector3 movement = new Vector3(moveHorizontal, moveVertical, 0.0f);
         GetComponent<Rigidbody2D>().velocity = movement * speed;
 
         GetComponent<Rigidbody2D>().position = new Vector3
         (
             Mathf.Clamp(GetComponent<Rigidbody2D>().position.x, boundary.xMin, boundary.xMax),
             0.0f,
             Mathf.Clamp(GetComponent<Rigidbody2D>().position.y, boundary.yMin, boundary.yMax)
         );
 
         GetComponent<Rigidbody2D>().rotation = -GetComponent<Rigidbody2D>().velocity.x * tilt;
 
         Debug.Log(moveHorizontal);
     }

I can not see anything wrong with it.

Thanks in advance

Comment
Add comment · Show 3
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 DoTA_KAMIKADzE · Apr 06, 2015 at 02:09 PM 0
Share

Could you use Debug.Log to post here your maximum moveVertical, moveHorizontal and speed values?

P.S. Also say what you expect it to move by.

avatar image RealMTG · Apr 06, 2015 at 02:13 PM 0
Share

@DoTA_$$anonymous$$A$$anonymous$$I$$anonymous$$ADzE I am not really sure what you mean but if I've understood you right, moveVertical gives the same values as moveHorizontal when I put it into the debug.log. It goes from -1 to 1. Just like moveHorizontal

avatar image DoTA_KAMIKADzE · Apr 06, 2015 at 07:22 PM 0
Share

Well your code is fine, I meant this:

In your code your X movement = moveHorizontal*speed; Y movement = moveVertical*speed; Z movement = 0;

So there can be either of 2 problems:

1)Your input Joystick/$$anonymous$$eyboard gives small value. If you use $$anonymous$$eyboard then Unity will simulate for few frames movement of Joystick, if you use Joystick then it gets Joystick position.

Anyway just go configure your axis in Input$$anonymous$$anager (Edit=>Project setting=>Input)

2)Your speed value is small so increase it.

P.S. Lulz, how did I miss it, you use 3D vector for 2D Rigidbody, use 2D vectors everywhere like that:

 new Vector2(moveHorizontal, moveVertical);

Or use 3D Rigidbody...

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Dan627 · Sep 12, 2017 at 04:48 PM

You need to use a Vector2 for your position. Change to:

GetComponent().position = new Vector2 ( Mathf.Clamp(rb.position.x,boundary.xMin,boundary.xMax), Mathf.Clamp(rb.position.y,boundary.yMin,boundary.yMax) );

@RealMTG

Comment
Add comment · 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

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

21 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

Related Questions

Xbox 360 vertical analog axis not working right? 0 Answers

How to restrict camera rotation to vertical axis? 2 Answers

Vertical axis not working properly 0 Answers

Input Scroll Wheel And Vertical Axis Work Together? 0 Answers

How to detect Double Clicking Horizontal/Vertical Axis on joystick 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