Search Unity

[SourceCode] Custom Character Controller Capsule Collision Detection

Discussion in 'Physics' started by HiddenMonk, Sep 5, 2016.

  1. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    974
    I have recently posted my character controller (which includes custom capsule collision detection) on github as open source (MIT license).
    When I say character controller, I mainly mean the collision handling and what not, similar to the unity character controller component. I dont mean a character controller such as one that handles walking animations and such.

    I have a whole wall of text with some images and videos so go check it out if youd like =).

    https://github.com/HiddenMonk/Unity3DCustomCharacterControllerCapsuleCollisionDetection

    Please read the README if considering using it. Near the top I explain some flaws that might be a game changer for you.
    I would consider this character controller a last resort ^_^.
     
    Last edited: Sep 5, 2016
    IEdge, ZhavShaw and Cybearg like this.
  2. saniasanjana16

    saniasanjana16

    Joined:
    Dec 3, 2015
    Posts:
    1
    Nice post.........
     
  3. Geckoo

    Geckoo

    Joined:
    Dec 7, 2014
    Posts:
    11
    I should try your custom character controller. It could help me to solve a problem with mine CC since I updated Unity. Thank you for sharing. I appreciate ++
     
  4. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    974
    hehe, I had just wrote that wall of text on the git page so my post here was somewhat short and crummy since all the info is there ^^.

    If its just a possible small bug on unitys character controller that is your issue, I would advise first trying to see if there is a fix before using this controller =).
     
  5. IEdge

    IEdge

    Joined:
    Mar 25, 2017
    Posts:
    28
    Thanks bro!
    It has been a great help to me!
     
  6. IEdge

    IEdge

    Joined:
    Mar 25, 2017
    Posts:
    28
    @HiddenMonk, I do not know if it's late but I have a couple of mistakes:

    1. I can not rotate my character to the desired angle, instead it rotates to weird opposed angle, why?.
    2. My characters "floats" in the air (does not stay on the ground), why is this?

    upload_2018-9-5_16-48-34.png

    EDIT: I solve #2 by change pivot point :cool:
     
    Last edited: Sep 6, 2018
  7. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    974
    wobes likes this.
  8. wobes

    wobes

    Joined:
    Mar 9, 2013
    Posts:
    678
  9. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    974
    I am not sure what you mean by manual simulating, but from what I think you mean then I dont think there is. Maybe if you give SubStepUpdater.Update a parameter float deltaTime that you can pass instead of just using Time.deltaTime and manually update the PlayerRigidbody subStepUpdater you might get framerate independent manual simulation?
     
    wobes likes this.
  10. wobes

    wobes

    Joined:
    Mar 9, 2013
    Posts:
    678
    Thank you.
     
  11. IEdge

    IEdge

    Joined:
    Mar 25, 2017
    Posts:
    28
    Hello, I could fix it by change localRotation of children objects, however, I'll take a look your solution. Thanks for your reply!.

    One last question: It is possible that you can add events OnCollisionEnter, OnCollisionExit...to this system?
     
  12. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    974
    I am currently not working on the controller, its been like 2 years since I really worked on it, kinda got tired of working on it and wanted to work on an actual game ^^.
    Adding a OnCollisionEnter, OnCollisionExit, etc... would probably be doable, but would most likely not act like unitys Rigidbody or like unitys CharacterController.
    It would probably need to be called within the PlayerRigidbody.GetCollisionSafeVelocity method, but here is where there may be issues. If we put it right as we detect the collision, even if we give the callback, we currently have no way to actually alter the velocity or anything while the GetCollisionSafeVelocity is already running.
    For example, I am pretty sure unitys Rigidbody gives the OnCollisionEnter and such callbacks after the collision was detected and everything is done running (basically after the physics update finishes you will get the callback), however, the rigidbody wont actually correct the collision until the next frame, so that leaves you time to actually alter the state of the rigidbody before the physics system does.
    Another example, unitys CharacterController has a OnControllerColliderHit(ControllerColliderHit), which gets called when you call the CharacterController.Move or SimpleMove and you collide with something. The CharacterController.Move method can be called at anytime and is not relying on any physics loop or something, which means if you call CharacterController.Move(Vector3.forward) and get the OnControllerColliderHit and then call CharacterController.Move(Vector3.back) within the OnControllerColliderHit callback, the result will be that you wont move at all.
    My PlayerRigidbody uses an update loop, so we dont have something like the CharacterController.Move, and my PlayerRigidbody changes the state of the transform on that same frame, which means we cant actually alter the PlayerRigidbody like we would have been able to with unitys Rigidbody.
    So if I would have added a OnCollisionEnter, it would probably need to be called after the GetCollisionSafeVelocity finishes and be to just show what the PlayerRigidbody had collided with in the past. Either that or have some way to allow altering the current PlayerRigidbody physics loop.