Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 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 nickmakesgames · Aug 19, 2018 at 08:05 PM · 2dtilemap

2D Tilemap Collisions

So I'm having trouble with 2D Tilemap collisions. My game is going to be a top down 2D RPG. In my game I have a player, which is currently just a sprite that can move up, down, left, and right. I also have a small map that I have been working on with my tileset. However, I have been having trouble adding colliders to the walls so that the players can't walk through them. I tried putting the walls on a separate grid and adding a tileset collider to just that grid, but it isn't working. My player does have rigidbody2d and tile map collider 2d on him so I'm not sure why it isn't working. I tried a polygon collider before where I had to outline the walls by hand. This was very inefficient but also led to a lot of glitches when my player collided with the wall, so I would really appreciate it if someone could give me some advice here. To clarify, I want my player to be able to move through some of the tiles (grass, paths, etc.) but not be able to move through the wall tiles. Thanks in advanced to anyone who can help.

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 RustyCrow · Aug 19, 2018 at 09:48 PM

So i am going to assume you know how to set up a tile (if not unity tutorial). I think what you are looking for is the Composite Collider 2D, simply put this component takes all the colliders in child(?) and makes them into 1 solid/connected. Here is a Unity talk where he sets up the Colliders for his tilemap. This should solve the problem i think you have(small gaps between 2Dbox colliders).

Now depending how experienced you are with unity, your problem might be alot more basic. If this dosent fix your issue, you need to give us a little bit more information, are you just walking up against the wall and just slipping past ? Are you 100% sure your collider setting are correct ?


After reading your comment with some new info i can add a couple more things.

I'm not slipping through the walls, but if I run into them at certain angles like at corners it will flip my character sideways or upside down and completely change the orientation of the game.

As mentioned by Austin-Gregory in the comments, if you look at the Rigidbody2D component you can restrict Rotations on Axis. This goes back to my settings suggestion(should have been more clear i ment in componants).

I'm pretty sure there's something wrong with my player movement code Is there anywhere I can find a more stable player movement script for top down rpgs

     // Use this for initialization
     void Start () 
     {
         Character = this.GetComponent<Rigidbody2D>();
     }
     
     // Update is called once per frame
     void FixedUpdate () 
     {
         DirectionX = Input.GetAxisRaw("Horizontal");
         DirectionY = Input.GetAxisRaw("Vertical");
         Character.velocity = new Vector2(DirectionX * Speed, DirectionY * Speed);
         //Debug.Log(DirectionX +" " + DirectionY);
     }


Here is some code that works with Rigidbody2D put it on you character.


The thing is @nickmakesgames the root if your problems i think is in understanding the basics. You need to take this 1 step at a time, I suggest starting with colliders and rigidbodies and then move on to tilemaps. Because in the end we might solve 1 problem right now, but in the future your gonna have a very simple problem again and trying to debug these types of problems takes more time then its worth especially if the OP dosent take the time to learn the basics. i dont want to discourage you from asking questions, a good question is hard to formulate that is why i say take it 1 step at a time.

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 nickmakesgames · Aug 20, 2018 at 12:37 AM 0
Share

I'm not slipping through the walls, but if I run into them at certain angles like at corners it will flip my character sideways or upside down and completely change the orientation of the game. I am just looking for a way to have two different tile maps. One for grass that I can walk on, and one for walls that I cannot walk on. Also, when I add the tilemap collider 2d to a different tilemap for walls as shown in the video you linked, I don't get the green boxes around the walls signaling that they have collision. I'm not sure what I'm doing wrong. Also, what should my collider settings be? EDIT: I downloaded the demo 2d game shown from the unity tutorial, and used my character ins$$anonymous$$d of the one they showcased. I'm pretty sure there's something wrong with my player movement code that makes it turn in different directions when it collides with tilemap colliders. Is there anywhere I can find a more stable player movement script for top down rpgs like what I'm trying to make?

avatar image Austin-Gregory nickmakesgames · Aug 20, 2018 at 06:45 AM 0
Share

For the weird rotating thing on collision, make sure to restrict the rotation axis on the Rigidbody2D. Rigidbody2DConstraints. You'll see these options in the inspector for rigidbody. I'm guessing what's happening is you have it set without restrictions, so physically colliding with a corner or wall will rotate the body around.

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

184 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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 programmatically switch tile palettes in Unity2D 0 Answers

Player ignores tilemap collider on fall 1 Answer

How to turn off the Import Popup of Tilemaps in 2021.2.14f1? 1 Answer

Unity2D Tilemap Add Sprites with Normal Maps to tilePallet 2 Answers

Generating tilemap palettes 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