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 IsraelVipe · Jul 12, 2018 at 02:38 AM · collisioncollider2dtilemapcollision2d

How to the detect what side of the player is colliding with a object in a tilemap

i'm making a 2d vertical scrolling game, all the world's objects (walls, obstacles, etc.) are part of tilemaps, when the player collides with any object i need to get what side of the player collided, i've tried all the answers in this post and found similar solutions on this forum, the problem is, all of them use the position of the colliding object to find the side, that worked when colliding with standalone objects but didnt work when colliding with tiles in a tilemap since the collider always return the same fixed position of the Tilemap object. I know there mey be another ways to solve this issue but i just dont know what to do to get this working properly.

Comment
Add comment · Show 1
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 JVene · Jul 12, 2018 at 11:53 AM 0
Share

I've not worked with tilemap objects, and I'm just thinking off the top of my head, so with that caveat, have you considered that since you have the tilemap and the object known at the time of the collision, perhaps you could check the world position of the colliding object against the position of the tilemap to calculate the relative position of the object at the moment of the collision?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by theGreatSlutze · Jul 12, 2018 at 12:01 PM

Can you use the position of the collision relative to the colliding player to figure out what side was collided with? When you receive a collision you should know the location of the collision. E.g. if it's greater than the X location of your player's center, but less than the extents of the player's bounding box on the Y axis, then you'd know the collision occurred on the right side of the player.

Comment
Add comment · Show 1 · 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 IsraelVipe · Jul 12, 2018 at 07:11 PM 0
Share

I think i've tried something like that before, but maybe not, could you please give me an example of what the code for this would look like?

avatar image
0

Answer by sisse008 · Jul 12, 2018 at 12:07 PM

there are only two sides right? left and right? why not put on the player a "right" collider and a "left" collider?

Comment
Add comment · Show 1 · 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 IsraelVipe · Jul 12, 2018 at 07:44 PM 0
Share

There is top and bottom collisions too, i put 4 trigger colliders around the player box collider, but the reason i'm asking here is because it doesnt work very well, sometimes it detects a top collision when its hitting a wall on the left and so on, that's how it looks like right now:

alt text

the front collider got this way when we tried to fix the issue i said above, but it generates other problems when like when a wall hits the uncovered regions of the trigger colliders, besides that i think it would be simpler do deal with all this without creating extra colliders, but im open to any solution that actually works.

player-collider.png (68.5 kB)

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

144 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

Related Questions

Composite Collider on Tilemap not really stopping player 0 Answers

How do I get collisions between Tilemap Collider 2d and a Kinematic Rigidbody 2d? 1 Answer

Weird ContactPoint2D on two BoxCollider2D collision 0 Answers

How do I set an object's velocity to the velocity of an object that collided with it? 0 Answers

How to detect on which exact tile a collision happened? 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