Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 fahricanelidemir · Dec 06, 2019 at 01:44 AM · physicsrigidbodyrigidbody.addforcerigidbody.velocityflipping

Problems with Physics(Flipping strangely)

There are a cube and floors in scene. I'm trying to move a cube on X axis with a script(I will need a jumping function on a key press later if i can solve this problem).
1. Cube has a Rigidbody which has 0 angular drag and 0 drag.
2. Both Cube and Floor have Box Colliders
3. Both Box Colliders have Physics Materials which has 0 friction.
4. Use Gravity on Rigidbody is active.
The problem is that the cube behaves really strange and flips and rotates even though I'm just setting a velocity on +X direction on a floor. I tried freezing constraints but then cube totally stops. Floors are 1 unit on X and Z axis since I am creating an endless path but they are next to each other seamlessly MyScene The scripts I have tried and didn't solve the problem :

  void FixedUpdate()
     {
         Vector3 velocity = rb.velocity;
         velocity.x = 5f;
         rb.velocity = velocity;
     }
  void FixedUpdate()
     {
         rb.AddForce(5f-rb.velocity.x,0,0,ForceMode.VelocityChange);
     }


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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Anis1808 · Dec 06, 2019 at 04:24 AM

I don't see errors in your code although I would simplify it to:

 Vector3 vel = new Vector3(5,0,0);
 rb.velocity = vel * speed; 

This said, have you tried moving it with simple transform.position movement ? Does it work when you remove gravity ? Does your box have a very large mass ? It all depends on multiple variables but I suggest you play around with values.

Comment
Add comment · Show 4 · 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 fahricanelidemir · Dec 06, 2019 at 12:10 PM 0
Share

I tried using position movement, it works better but if there is a wall, it tries to enter inside wall. Also I need a gravity for later. I tried many things after that but couldn't find any answer.

avatar image Anis1808 fahricanelidemir · Dec 06, 2019 at 01:25 PM 0
Share

If you don't have a friction i really dont understand what is happening, can you post a picture of your scene because the one you posted didnt load.

avatar image fahricanelidemir Anis1808 · Dec 06, 2019 at 04:49 PM 0
Share

Flips like this at start Also if I freeze rotation on Z, it won't move, just stucks at the first tile.

avatar image Anis1808 fahricanelidemir · Dec 06, 2019 at 06:23 PM 0
Share

I have tried replicating your problem but I am not able, can you try a new clean scene and put a plane ins$$anonymous$$d of floors? If it works, can you use a cube from unity? $$anonymous$$aybe the collisions make it act this way

avatar image
0

Answer by lgarczyn · Dec 06, 2019 at 07:09 PM

This is likely caused by very small imperfections on the floor colliders. Your cube basically gets stuck on the small ridges of the floor caused by the different columns.

You can

  1. Make every flat surface is a single collider

  2. use a CharacterControllerroller instead of a Rigidbody

  3. Change the cube collider so that it has small bevels on the side and doesn't get stuck

  4. Use 2D physics since the game appears to be mostly 2d gameplay with 3d graphics.

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 fahricanelidemir · Dec 06, 2019 at 07:30 PM 0
Share
  1. $$anonymous$$y path script doesn't work like that so I used 4th answer.

  2. I couldn't find a good way to use it with jumping, need a tutorial.

  3. ?

  4. It works pretty good for now. I will add some new mechanics and will see how it works. (Edit : my bad, it still flips :( )

Thanks anyway. I will try 2nd and 3rd answer soon.

avatar image lgarczyn fahricanelidemir · Dec 07, 2019 at 07:00 PM 0
Share

2d physics won't help you too much with this exact problem, but will give your more options.

Simply generate a PolygonCollider2D for your player, then edit it to round the corners. Then just freeze the rotation.

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

219 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 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 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 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 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 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 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 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

Rigidbody.velocity seems to be breaking jumping physics 0 Answers

VR Sword Physics, how to add force or velocity to the sword for impact when it hits an object 1 Answer

Setting a RigidBody's velocity messes with my custom gravity, not sure how to proceed. 0 Answers

Any way to gracefully detach object with Unity physics? 2 Answers

Moving rigidbody (Player) with addForce or Velocity ? 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