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 SarumanTheWight · May 27, 2019 at 07:07 PM · collision detectioncollider2dplatformercollision2d

How do I make object only collide with certain objects based on position of collision within the collider?

I am making a 2D platformer. The character is a 100X100 sprite that has about 20 pixels blank at the bottom. The purpose of this is to give the illusion of floating. The player's collider goes to the bottom of its sprite and the platforms have edge colliders on the very top of them. The issue is that if a player hits an enemy or obstacle from above, the player hits it when the collider (below where the player visually is) hits the obstacle. What I want to do is simply say that the collision with the obstacle occurs only at a lower point, but I don't even know if this is the right approach. I'm open to ideas of any kind.

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
0

Answer by highpockets · May 27, 2019 at 09:24 PM

In a situation like this, I would opt for 2 colliders and get the lower one to ignore collisions with everything except for the ground and the other one can collide with enemies/obstacles/etc. You can use the layer collision matrix to define what collider layers to ignore. Check out this post:

https://answers.unity.com/questions/686915/how-do-i-get-some-objects-to-ignore-collision-with.html

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 SarumanTheWight · May 27, 2019 at 09:33 PM 0
Share

Thanks @highpockets , how do I make 2 separate colliders that use the layer collision ignore if it goes by tag and they both have the same tag (because they're attached to the same object). I had originally tried to do this using 2 children and attaching the colliders to the children that each had a different tag, but the collider that actually prevents the user from falling through the platforms doesn't hold the player up unless it's attached to the player. I then tried keeping that one on the player, but then the problem was that the collider labelled player was not colliding with the obstacles while the other one was. I guess this is okay, but it seems like a very non-correct and non-elegant way to hack around it. Can you label the 2 colliders on the player seperately? That would be a lot cleaner.

avatar image highpockets SarumanTheWight · May 27, 2019 at 09:41 PM 0
Share

Well the layer matrix is the way to do it in the editor, and having the bottom one a child of the top one and then putting the layers on them and defining what you need in the matrix is one way to do it.

You can also use the Physics.IgnoreCollision() function:

https://docs.unity3d.com/ScriptReference/Physics.IgnoreCollision.html

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

113 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

Related Questions

How to check from which side a gameobject collide? 0 Answers

How to set collision for an object with specific collider size? 3 Answers

Bullet hit the collider of a child object 1 Answer

multiple objects on oncollissionstay2d 1 Answer

Collision detection problem 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