• 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

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

Related Questions

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

How do I detect which collider is being collided with? 0 Answers

Unity 2D Collision checking 1 Answer

Stuck Between tilemap colliders 0 Answers

Collision detection problem 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges