• 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
4
Question by AaronG · Aug 03, 2011 at 08:46 PM · c#physics

Ensuring completely smooth movement along a series of box colliders

I am making a puzzle game which involves objects moving around a level influenced by gravity.

Sometimes an object will fall 'freely', IE, in mid air. Other times, an object will fall whilst brushing a flat surface comprised of a series of box colliders that are perfectly aligned with each other.

The issue is that objects that are brushing along the box colliders will fall slightly slower and sometimes they will bounce away from the surface at the point where two box colliders meet.

Here's an image more clearly demonstrating what the issue is.

http://dl.dropbox.com/u/1008157/Indie/physics-fig1.png

Obviously this is very annoying and isn't what I want.

There is 0 friction on each surface, there is 0 friction set in the physics material, both objects are completely identical in mass, drag, and the box colliders are perfectly aligned with each other.

I don't wish to use a single box collider that covers the entire surface as I would really prefer to stick with my modular approach of level design which makes propogating changes across multiple levels incredibly easy.

So my question is how can I solve this problem?

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 Meltdown · Aug 03, 2011 at 09:08 PM 0
Share

lol, love your diagram :)

avatar image TheDarkVoid · Aug 03, 2011 at 09:35 PM 0
Share

nice diagram

avatar image aldonaletto · Aug 03, 2011 at 11:38 PM 0
Share

This diagram deserves my vote. Why don't you insert the image in the text?

2 Replies

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

Answer by TheDarkVoid · Aug 03, 2011 at 09:36 PM

the problem is the the physics in unity is not perfect and the falling box may be too close to the wall try offsetting it by about .01, you can also select freeze rotation in the rigid body options

Comment
Add comment · Show 3 · 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 aldonaletto · Aug 03, 2011 at 11:36 PM 0
Share

Yes, I think freezing rotation may help. The problem probably is caused by the abrupt change in normals at the edges - physics simulation must calculate the contact points and normals, and at the edges this probably gives crazy results.

avatar image AaronG · Aug 04, 2011 at 02:07 PM 0
Share

Ah yes. Offsetting did the trick! Here's the method I wrote to fix up the position.

float rayDistance = 4f; // Distance to raycast

float moveDistance = 0.5f; // Distance to translate object

// Raycast in 4 directions to check if we're hitting something

// Up

if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.up), rayDistance)) transform.Translate(new Vector3(0, -moveDistance, 0));

// Right

if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.right), rayDistance)) transform.Translate(new Vector3(-moveDistance, 0, 0));

// Down

if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.down), rayDistance)) transform.Translate(new Vector3(0, moveDistance, 0));

// Left

if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.left), rayDistance)) transform.Translate(new Vector3(moveDistance, 0, 0));

avatar image TheDarkVoid · Aug 04, 2011 at 02:32 PM 0
Share

nice, maybe i can use this later too

avatar image
-1

Answer by Instability · Jun 10, 2013 at 11:24 AM

Alternatively, you could create an empty gameobject and attach a box collider for the ground to it. You could use collision layers to make sure the ground collider does not interfere with the rest of the geometry, only with the player. Set the ground collider a tiny bit above the (uneven) floor geometry and it should roll smoothly. You can make the ground collider stretch large patches and it will be a continuous object.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

Trouble Understanding Vector3.Angle() Result 2 Answers

How to make a system that will let elements interact with other elements? 1 Answer

C# Check if Collider2D[] Doesn't contain Scripted GameObject 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