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 LMitch123 · Apr 07, 2014 at 06:26 PM · movementinputy axis

Character object inexplicably jumps up on the Y axis when arrow keys are pressed to move it along x or z

Hello,

I'm hoping somebody can shed light on this Unity problem I have. I'm very new to all of this (both Unity and programming beyond goto print), so I apologise in advance if this is really obvious and I've just missed it after several hours of trying random fixes and glaring at my monitor.

I have a character object (a parent composed of three child objects) which is controlled along the preset Horizontal and Vertical axes. I cobbled together a script which appeared to make the character happily move along the floor in any direction and stop almost as soon as the player stops pressing any of the four arrow keys (as required). However, when any of the arrow keys are pressed, the object jumps from y=2.5 to y=4.38 and hovers in the air from then on. I tried setting the Freeze Y Position constraint on the object; this stopped the object from ending up in the air, but slowed movement down greatly and prevented any movement at all when pressing the up or right arrow keys.

I have no idea what's causing this; I've included my movement script below for reference. If anyone can shed light on this, I'd be very grateful.

 {
     public float speed;
     
     void FixedUpdate () 
     {    
 
         float moveHorizontal = Input.GetAxis ("Horizontal");
         float moveVertical = Input.GetAxis ("Vertical");
         Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
 
         if (Input.GetAxis("Horizontal")!=0)
         {
             rigidbody.AddForce (movement * speed * Time.deltaTime);
         }
 
         else if (Input.GetAxis("Vertical")!=0)
         {
             rigidbody.AddForce (movement * speed * Time.deltaTime);
         }
 
         else 
         {
             rigidbody.velocity = Vector3.zero;
             rigidbody.angularVelocity = Vector3.zero;
             rigidbody.Sleep ();
         }
         
     }
 }

EDIT: So... I was looking further into this; turns out that if you check the Convex setting on the Mesh Collider of a Plane, it causes all kinds of funky behaviour (as your character object effectively tries to move along an invisible curvature of your game scene). I thought I could leave this here for fellow noobs who might have stumbled into the same issue, but I'm happy to delete it if requested.

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 Klarax · Apr 08, 2014 at 11:43 AM 0
Share

might be the Vecotr3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);

This might need to be something like:

Vecotr3 movement = new Vector3(moveHorizontal, transform.position.y, moveVertical);

cos it might have a strange position for y, and is using that ins$$anonymous$$d of what you think....

hope that is a) correct and b) makes sense

avatar image LMitch123 · Apr 09, 2014 at 10:00 AM 0
Share

Thanks, $$anonymous$$larax - the edit I wrote above seems to have done the job, but I'll definitely take a look at this.

avatar image ExiledFoG · May 31, 2015 at 11:44 AM 0
Share

Thank you L$$anonymous$$itch123 That was my problem I must have clicked it without knowing

I can go to sleep now ;) Thanks for posting

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

23 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

Related Questions

New Input System 'Started' and 'Performed' actions fire at the same time? 1 Answer

Add keyboard input in ClickToMove 0 Answers

Alternative to transform.Translate? 3 Answers

Shooting in direction of the character movement 2 Answers

I Watched The Unity New Ball Rolling Game Tut, How I Can Make Jump,I Watched The New Unity Ball Rolling Tutorial, How I Can Make Jump? 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