Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question 2D building game character bumps in even surface / sticks to walls

Discussion in '2D' started by HMIMH, Sep 5, 2020.

  1. HMIMH

    HMIMH

    Joined:
    Oct 15, 2017
    Posts:
    7
    I'm trying to make a 2D game, Terraria / Starbound like, as main concept. But I don't seem to get the right character controller at all. If I go with Rigid bodies (which seems optimal), my character bumps going on a straight line, even if the tiles are perfectly aligned (picture).
    To solve this someone suggested using composites, but it didn't let me destroy tiles anymore like that (I'm using a raycast, and if it hits a tile, destroy that tile. For building I clamp coordinates to integer based on mouse world position < is this even the right way to go?). Also, if you hold left or right key towards a wall, you stick to it. Tried the 2d physic material with 0 friction everywhere. Still sticks.. Any solution? Thank you so much in advance


    I have also tried 4-5 different controllers, including the Brackeys one where it uses 2 collider boxes. bumps.PNG
     
  2. HMIMH

    HMIMH

    Joined:
    Oct 15, 2017
    Posts:
    7
    I tried going without physics. Works well, but when I jump and I hit a ceiling, it keeps flying for a few seconds. Since it's pushing up.. I rather going with rigidbody.
     
  3. PuppyPolice

    PuppyPolice

    Joined:
    Oct 27, 2017
    Posts:
    116
    Have you tried using a capsule collider on your player? The rounder edges tends to help.
     
  4. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,319
  5. HMIMH

    HMIMH

    Joined:
    Oct 15, 2017
    Posts:
    7
    Yes, I have tried. The player keeps bumping in the same way

    Thank you for the video. Indeed, I did it in this way already. It removes the bumping, but if I do that I'm not able to destroy the tiles anymore, since now all of them create a new single shape. I would like to treat each tile individually so they can be destroyed. At least, my raycast with destroy(gameObject) stops working with the composite
     
  6. PuppyPolice

    PuppyPolice

    Joined:
    Oct 27, 2017
    Posts:
    116
    So composite collider work but then destroying does not work? How about trying to destroy the tiles through the tilemap, use a raycast, get the position of the tile, get the tilemap.setTile(position, null); might work?
     
  7. HMIMH

    HMIMH

    Joined:
    Oct 15, 2017
    Posts:
    7
    Composite collider works to solve the bumping issue, since now it's an even surface. What doesn't work is destroying tiles with this little system I made

    Code (CSharp):
    1.  RaycastHit2D rayHit = Physics2D.GetRayIntersection(Camera.main.ScreenPointToRay(Input.mousePosition));
    2.  
    3.  
    4.          
    5.             if (rayHit.collider != null && rayHit.collider.name != "player")
    6.             {
    7.          
    8.                
    9.                     Destroy(rayHit.transform.gameObject);
    10.                 }
    11.  
    12.             }
    13.  
    I'm going to try with your solution. I will have to make some changes, since I'm not working with tilemaps!