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 /
  • Help Room /
avatar image
0
Question by redsawq4 · Sep 03, 2015 at 05:06 AM · 2d2d-physics

Top down 2D collision: How do I prevent players from getting "stuck" in walls?

In my game, the player moves using velocity until they run into a collider (Up, down, left or right). They cannot redirect their movement once moving. However, if they are directly touching a collider, they can move into it (again) and get "stuck" in the wall, unable to move again because it reads as moving.

Using a Raycast does not seem to work because if the player is already touching a wall, their collider is already slightly inside of it and it seems to ignore the collider. Currently, I am using a bool to check whether or not the player just moved in a specific direction, essentially preventing them from moving in the same direction 2 times in a row. However, if they run into a corner, this problem can still occur.

Is there any way to check the direction of a collision? Or a simple solution to this problem? I am in the process of learning C# and would greatly appreciate some assistance. Thanks in advance!

Comment
Add comment · Show 2
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 Positive7 · Sep 03, 2015 at 06:28 AM 0
Share

Try to attach Physics $$anonymous$$aterial to wall with no friction.

avatar image redsawq4 · Sep 05, 2015 at 06:17 PM 0
Share

Hey @positive7 thanks for the quick response! I have tried that and that doesn't seem to do anything. i think that once I run into the wall, he just gets stuck and the code I have basically reads that he is moving, however, he is stationary running into the wall.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Europa012 · Sep 09, 2015 at 06:10 AM

Why not try this? Once the object hits a wall, set the movement speed to 0 from within the script. and make sure that the mass of the walls are big.. something like 99999 could to it. That is, if you don't mean them to move or anything. and if there is no gravity. Hope this helps

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
avatar image
0

Answer by lloladin · Sep 24, 2015 at 09:16 AM

first of all are you using a box/colliders/cirkel/colliders?

if you are using a box colliders this should fix all youre problmes if you go to youre rigidbody and change the collision detections to continuous this will take more computer power but it will also make the collision detections work better

if you are a using a cirkel collider the problem could be that the edges of the cirkel colliders are getting stucked in walls which i personnaly solved by using a mix of box colliders and cirkel colliders to remove the edges of the top of the cirkel i can send a picture if you need

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.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Player controlled platforms 0 Answers

Getting rid of 2D collision jitter 1 Answer

Help 2D Custom HillClimbRacingGame 0 Answers

How can I slow the movement of a single rigidbody2D? 2 Answers

[2D] Rigid body snaps through floor and back 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