Search Unity

Help with Character Movement

Discussion in 'Physics' started by wagenheimer, Mar 4, 2021.

  1. wagenheimer

    wagenheimer

    Joined:
    Jun 1, 2018
    Posts:
    323
    Hi! I'm trying to create a simple character, that just walks on the scene, pushes objects, and travels through moving bridges!
    upload_2021-3-4_15-9-40.png

    I found a code that handles the input regardless of the camera's position and it works very well.
    I have a simple example scene here:



    - Each floor box does use a Box Collider
    - The Mummy is a Capsule Collider

    But we can see 3 major problems :

    - When pushing the Blue Box, sometimes it gets stuck up and I can't push it any further.
    - When climbing the rotating bridge, the character moves along with the bridge! Which is perfect. But if I try to walk on the rotating bridge, it rotates like crazy!
    - It can even climb stairs, but with VERY difficulty, almost impossible. =)

    I attached the complete project here for those who want to take a look.

    Would anyone have any idea how to fix and improve these features or do recommend some Assets that will handle all of them?

    Thanks!
     

    Attached Files:

  2. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    2,254
    We have an asset (Sticky3D Controller) which most likely solves your problems. You can read about it here.
     
  3. wagenheimer

    wagenheimer

    Joined:
    Jun 1, 2018
    Posts:
    323
  4. Deleted User

    Deleted User

    Guest

    Give your player a Physic Material with no static or dynamic friction. Rigidbody characters need that on their colliders, or they get stuck constantly. Give it full rotation constraints in the inspector to fix it on the rotating ramp also. Tell me if it helps! ;)
     
  5. DimitriX89

    DimitriX89

    Joined:
    Jun 3, 2015
    Posts:
    551
    Step handling is a big problem in character controllers, since when the movement vector is aligned to the ground plane, moving forward presses character into obstacle (assuming it is close to the 90 degrees to ground) instead of somehow moving over it.
    You'll need some method of detecting such "steps", and then apply vertical force to the character to resolve stucking. The easiest way is to project a Raycast in the direction of movement (from the origin slightly above the ground so it doesnt give false positive), and while it is "true", constantly apply upward thrust to the character.
     
  6. DevCas1

    DevCas1

    Joined:
    Sep 24, 2015
    Posts:
    21
    Maybe set the box-to-be-pushed's position to be slightly above the ground, so it'll never physically touch the lower boxes?