Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Woolert · Sep 18, 2020 at 12:41 AM · 2d game2d-platformercolliderstilemap2d-physics

Using a Tilemap Collider 2D, and my rigidbodies keep getting stuck inbetween tiles. Is manually placing Edge Collider 2Ds my only solution?

Hi there. I'm working on learning some of Unity's newish 2D features, and I'm looking at tilemaps and tilesets. Right now, I'm trying to decide between using a Tilemap Collider 2D or a series of 2D Edge Colliders for managing solid objects in a level. For reference, here's what the colliders look like:


Tilemap Collider 2D (Many automatically placed squares and triangles): Tilemap Collider 2D

Edge Collider 2D (2 manually placed edge colliders): Edge Collider 2D


The Tilemap Collider is great because it's automatic, but I'm running into an issue where my player object, a 2D rigid body, is occasionally getting stuck in between the tiles as its moving. Looking online for solutions, people seem to be suggesting that this is just how this collider works, they suggest using edge colliders instead. Edge Colliders do in fact solve my issue, but now I'm faced with the arduous task of outlining each level, each iteration of a level, with hundreds of these silly lines. So my questions are:


  1. Is there a way to fix the Tilemap Collider so that it works properly, someway to keep player objects from tripping over tile boundaries and getting stuck on walls? Is there some sort of physics settings I can change in the project settings? Something on the attribute maybe?


  2. If this is how Tilemap Colliders just work, what is even the point of them? Is this a bug that is going to be fixed, or is it just 'as is'?


  3. If edge colliders are my only option, how can I automate it to work on a tile map to make it a viable option? Is there some hidden feature to somehow convert a tilemap collider to a series of edge colliders? I can't seem to find it if there is.


For extra info, here's the code I'm currently running for my player object. It's very basic at the moment:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Test2DPlayer : MonoBehaviour
 {
     private Rigidbody2D rb;
     private Vector2 moveVelocity;
 
     public float moveSpeed;
 
     //All used to see if player is standing on solid ground
     public bool isGrounded = false;
     public Transform isGroundedChecker;
     public float checkGroundRadius;
     public LayerMask groundLayer;
 
     // Start is called before the first frame update
     void Start()
     {
         rb = GetComponent<Rigidbody2D>();
     }
 
     // Update is called once per frame
     void Update()
     {
         Vector2 moveInput = new Vector2(Input.GetAxisRaw("Horizontal"), 0);
         moveVelocity = moveInput.normalized * moveSpeed;
     }
 
     private void FixedUpdate()
     {
         //rb.MovePosition(rb.position + moveVelocity * Time.fixedDeltaTime);
 
         rb.velocity = rb.velocity + moveVelocity;
         CheckIfGrounded();
     }
 
     void CheckIfGrounded()
     {
         Collider2D collider = Physics2D.OverlapCircle(isGroundedChecker.position, checkGroundRadius, groundLayer);
         if (collider != null)
         {
             isGrounded = true;
         }
         else
         {
             isGrounded = false;
         }
     }
 }


Thanks for your help! Let me know if you need more info!

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 Woolert · Sep 18, 2020 at 12:44 AM 0
Share

$$anonymous$$y images didn't post aparently, so I'll try again:

Tilemap Collider 2D:

https://imgur.com/kOvTKSB

Edge Collider:

https://imgur.com/5mrViKZ

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Woolert · Sep 18, 2020 at 02:23 AM

Found a possible solution: https://gamedev.stackexchange.com/questions/168600/player-gets-stuck-on-edges-between-tilemapcollider2d-tiles

Essentially:

 1) For the TilemapCollider2D check the box "Used by Composite".
 
 2) Then add the Component CompositeCollider2D (Found under Physics2D). 
 
 3) This will automatically add a Rigidbody2D to your object if it doesn't have one already.
 
 4) Change the "Body Type" of the Rigidbody2D to Kinematic unless you want physical interaction with the tilemap.
 
 5) Profit.
 
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

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

Built game doesn't work as the game preview 0 Answers

I just want to understand why when i check Is Trigger on my 2D player he dont collide with any layer but my trigger works fine instead of when i uncheck Is Trigger he collided and works i really want to to knew 1 Answer

What is the simplest way to get a jelly like effect in unity? 0 Answers

Player can only jump once!? 0 Answers

C# delaying command 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