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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by DeuS · Jan 17, 2015 at 05:12 PM · physicsrigidbodyaddforcetile

Object jumping while moving(with addForce)

I have a level build with 3d tiles, and when a player move with rigidbody.AddForce(with any ForceMode) he starts jumping: alt text

All tiles(simple cubes) has size 1.5 and placed properly(cube 1 pos.x = 0, cube 2 pos.x = 1.5 and etc.). If i remove colliders from tiles and make only 1 big collider, all work fine.

Movement code:

     public float Speed = 10;
     public ForceMode Mode = ForceMode.Acceleration;
     public KeyCode KeyRight = KeyCode.D;
     public KeyCode KeyLeft = KeyCode.A;
     void Start()
     {
 
     }
 
     void Update()
     {
         if (Input.GetKey(KeyRight))
         {
             rigidbody.AddForce(Vector3.right * Speed, Mode);
         }
         if (Input.GetKey(KeyLeft))
         {
             rigidbody.AddForce(Vector3.left * Speed, Mode);
         }
     }

Player object:

alt text

Anyone know how to remove this jumps?

moveproblem.gif (178.2 kB)
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 chariot · Jan 19, 2015 at 03:06 PM 0
Share

Try to freeze position in x axes. Box jumpes cause u freeze z axes :)

avatar image Simon-Larsen · Jan 19, 2015 at 03:55 PM 0
Share

I agree with Chariot. But I think that it's the y-axis that should be frozen. Would it break your game to unfreeze the y-axis only when the player jumps or something makes the player go flying - and then re-freezing it once you're grounded again?

avatar image DeuS · Jan 19, 2015 at 06:07 PM 0
Share

In the project I did it, but now I want to find a solution without freezing Y position.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Simon-Larsen · Jan 17, 2015 at 05:20 PM

Replace the box collider on your player with a sphere collider or capsule collider and all should be good :)

Comment
Add comment · Show 2 · 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 DeuS · Jan 17, 2015 at 05:32 PM 0
Share

Still jumping. alt text

moveproblem_capsule.gif (347.3 kB)
avatar image Landci · Apr 13, 2015 at 09:40 PM 0
Share

i am having the same problem with a capsule collider in Unity 5.0.1f1 i am trying to make an endless runner where my character walks and the road is built up with objects that have a collidersame scenario as stated above, sometimes it works sometimes it just hops up. i cannot contra

avatar image
0

Answer by hav_ngs_ru · Jan 19, 2015 at 09:08 AM

i guess it jumps because of friction that causes some torque, and rude rotation constraint calculations..

try set angular drag to any huge value first.

if it not help - try setup custom physics material: set allfrictions to 0, and set drag greater than 0 (in other words - replace surface friction by drag).

Comment
Add comment · Show 7 · 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 DeuS · Jan 19, 2015 at 10:50 AM 0
Share

Doesnt help, still jumps. I think the problem in several colliders, since with one all right. But do not know how to solve it, because one сollider does not suit me. alt text

moveproblem_doublescreen.gif (302.0 kB)
avatar image hav_ngs_ru · Jan 19, 2015 at 03:01 PM 0
Share

seems like you are right, your cube clings to tiles corners... try to uncheck z-rotation constraint to test it (and set friction and drag settings as it was before). If cube will cling corners and somersault ins$$anonymous$$d of jumping - assumption will be confirmed, and then we'll try to find solution...

avatar image hav_ngs_ru · Jan 19, 2015 at 03:08 PM 0
Share

are your tiles placed with exactly same y-coords and scale? are they closely adjacent to each other? couldn't it be some roughness on junctions or gaps therebetween?

avatar image DeuS · Jan 19, 2015 at 06:03 PM 0
Share

Yes, tiles placed correctly, they all with same scale and placed with grid snap. Uncheck z-rotation(same behavior with one collider and tiles colliders): alt text

moveproblem_withoutzrotation.gif (236.5 kB)
avatar image hav_ngs_ru · Jan 20, 2015 at 10:30 AM 0
Share

well... seems like it's because of a physics inaccuracy, because I dont have any assumptions :)

so question is not like "how to fix" but "how to workaround this bug"... I have one idea, but it needs to be confirmed... lets make one more experiment: sphere collider with no constraint on z-rotation. if it will just rotate (not jump) - you could make 2 gameobjects connected with hinge joint: first one is invisible, with sphere collider with no z-rotation constraint, and second one is visible box with no collider and with constrainted z-rotation. First one will smoothly roll, nd second will make illusion of sliding...

but if it will still jump... then i'm afraid that it will be better for you to review you scene architecture (possible you will need to make a single box collider to wrap you in-line tiles at runtime, to make your floor absolutely flat, or smh like this...)

Show more comments

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

29 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

Related Questions

How do I add force To rigidbody based On Character's Walking direction? 0 Answers

How to make rigidbodies on each side of a cube fall towards the cube? [multiple gravity / addForce] 0 Answers

Erratic Physics behaviour while testing in 2 computers 0 Answers

Prevent Rigidbody From Rotating 3 Answers

How to get spring to settle? 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