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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

custom character physics bug

Discussion in 'Physics' started by erandros, Sep 25, 2015.

  1. erandros

    erandros

    Joined:
    Sep 23, 2015
    Posts:
    6
    Hello people at Unity forums. I appreciate the time taken to read and answer this.

    I'm not using Unity's character controller. I'm rolling up my own character because I want it to have physics. I later on explain this decision. I'm doing a minecraft clone and I have this problem:

    If I create a plain floor made of 50x50 consecutive cubes, when I apply a force in a direction to the character to move it (which is on top of that floor), it moves, but sometimes the character comes to a full stop and I can't move it in that direction anymore. I can though go in the opposite direction and again try to go through the part I get stuck and most of the times it does get through, so this feels pretty random.

    The exact setup for my character is this: Character is a game object parent. It has a rigid body attached with default settings (including gravity turned on). It has as a child, the CubeCollider game object, which has a BoxCollider component attached in the form of a (1,1,1) box. The rotation of the Character is fixed in every dimension. And the cubes that compose the floor are just Unity's Physics -> Cube.

    I wonder if this whole setup is a bad idea or if only a part of it is.

    I don't want to use Unity's Character Controller because the shape is a capsule. I don't want that because of this
    .
    That is not how minecraft behaves. There's no sinking at borders.
     
    Last edited: Sep 28, 2015
  2. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    Hi erandros

    If you really have to create such setup for floor (instead of using one large collider) have you tried using sphere collider instead of box collider?

    I think you won't gain anything using box collider, you can limit rotation of spherical / circular colliders so that they don't tip over.
     
  3. erandros

    erandros

    Joined:
    Sep 23, 2015
    Posts:
    6
    They don't tip over. They just sink as shown in the video. This makes sense because the character is a capsule.

    Because of that, I don't want it to be a capsule. I want it to behave as a box. If all I'm doing is dragging a box on top of consecutive boxes, then why does it get jammed?
     
  4. erandros

    erandros

    Joined:
    Sep 23, 2015
    Posts:
    6
  5. Rostam24

    Rostam24

    Joined:
    Mar 5, 2014
    Posts:
    119
    Mind sharing a video of how it gets stuck? Because if it is what I'm thinking of right now, you should use an edge collider for the floor.
     
  6. erandros

    erandros

    Joined:
    Sep 23, 2015
    Posts:
    6
    This is a 3d game. Edge collider exists only in 2d. You're on track though.
     
  7. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    987
    I ran into a situation similar to this. What I ended up doing was creating a custom mesh collider in the shape of a capsule with a almost completely flat bottom. It was slightly curved so that it can still go over small edges on the floor.
    The problem was, even with this, friction was causing issues. As a result, I ended up putting a physics material with all values to 0 and friction / bounce set to minimum on my collider.
    This basically means that physics material will no longer affect my character and I will have to handle that on my own with custom friction components, however, I saw it as a good trade off.