Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Bonfi_96 · Mar 17, 2016 at 12:45 AM · resolutioncharacter controllerdetectioncollsionpushback

Collision resolution in tight spaces

I'm trying to implement collision detection on my character controller so I'm using the pushback method. Everything works fine except when I have two colliders that are placed in a similar way to the image, making a really tight "angle". Those two colliders could be two box colliders, or any other kind of colliders, the issue is that, after applying the pushback vectors the player collider is still overlapping with one or both of the "walls". This results in a sort of jittery back and forth movement as the script solves the collisions frame by frame until there are no more collisions.

Here's an awesome ms paint drawing that sums up the situation. alt text

Is there a better way to solve this kind of collisions? A quick work around would be to repeat the collision detection more times per frame untill the collision is completely solved but this doesn't sount to me as a good solution.

Thanks!

collision.png (11.4 kB)
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

1 Reply

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

Answer by Bunny83 · Mar 17, 2016 at 04:54 AM

Well, when adding all correction vectors with their proper magnitude together you get a new correction vector that has the correct direction, but the wrong magnitude. To get the correct magnitude you simply project the combined correction vector onto one of the original correction vectors. The magnitude of that projected vector would be smaller than the initial calculated magnitude that is needed to push the object away from that contact point. The ratio between the magnitude of the initial correction vector and our projected vector is the amount you need to scale the combined correction vector.

This should work in theory:

 Vector3 A; // left correction vector
 Vector3 B; // right correction vector
 Vector3 C = A+B // combined correction vector
 Vector3 P = Vector3.Project(C, A); // projected vector
 C = C * A.magnitude / P.magnitude;

This also corrects the magnitude if you have a wide angle where the correction would be too large instead of too small.

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 Bunny83 · Mar 17, 2016 at 05:09 AM 0
Share

Just to explain why this is necessary:

If the angle between your two walls is smaller than 90° the partially cancel each other out since the vectors point in opposite directions.

If the angle between the walls is greater than 90° the vectors actually accumulate partially since they now partially point in the same direction.

avatar image Bonfi_96 Bunny83 · Mar 17, 2016 at 10:59 AM 0
Share

Thanks, I'll try this out with code as soon as I can. How can I adapt with more than two colliders? Is it enough to project the C=A+B+D+.... on any of these vectors? I understand your explaination about vectors cancelling eachother out but I still can't get why the magnitude ratio is the one that solves the problem (for acute angles P's magnitude is smaller than A's so the ratio is >0, therfore the player gets pushed back more preventing other intersections)

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

52 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

Related Questions

How to detect in which half of the screen the cursor is, no matter the resolution? 1 Answer

Player jumps a different height when changing player aspect ratio (resolution) [Edit CPU also involved] 1 Answer

collision between character controllers 1 Answer

collistion detection with moving gameObject 0 Answers

Collision on character controller (fps player) 2 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