Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Physics Based Character Controller

Discussion in 'Assets and Asset Store' started by nappin_zz, Jan 26, 2022.

  1. nappin_zz

    nappin_zz

    Joined:
    Nov 15, 2017
    Posts:
    42


    https://assetstore.unity.com/packages/tools/physics/physics-based-character-controller-203438

    What is it?

    Physics Based Character Controller is a powerful yet simple character controller based on the unity physics system. The player can easily interact with the physical environment, move and push objects, slide on surfaces, climb, wall jump and so on...



    How do I use it?

    Simple: install the package, setup a camera (the package uses cinemachine but can work with custom cameras) and the input reader and you are ready to go! The package accommodates the user who wants a simple plug and play solution and also developers who want to add their own modifications on top of the existing code.



    What's included?

    The package contains:

    • Player model and multiple obstacle meshes
    • Prefab folder with all the "core" components
    • A sample scene that guides the user and allows them to experiment with the character controller and find the best parameters combination for their needs

    The package main features are:

    • Basic character movement in third and first person
    • Player can move the character and rotate the camera
    • Player can perform jump, long jumps, wall climb, wall slide, crouch, climb and sprint
    • Camera solution to avoid clipping with the objects in the scene
    • Capsule based collision and simple interpolated movements
    • Allows the player to walk on rubble and irregular terrain
    • Allows the player to walk on smooth terrain with changing normals
    • Allows the player to move up a slope within a certain angle limit
    • Ground snapping so the player can stick to surfaces and slopes
    • Allows the player to move on steps (within a certain height set by the player)
    • Supports rigidbody interaction and allows the player to move and collide with rigidbodies
    • Supports and ignores specific layers
    • Contains prefab that simulate viscosity
    • Contrains speedup and slowdown platforms
    • Contains bounce platforms
    • Contains moving platforms
    • Contains rotating platforms that keep the player rotation locked

    If you have any questions, suggestions or feedback, please feel free to contact me at nappin.1bit@gmail.com
     
    Last edited: Jan 27, 2022
    ml785 and Arkade like this.
  2. GrooGadgets

    GrooGadgets

    Joined:
    Apr 2, 2009
    Posts:
    71
    Hey,

    Does this asset support root motion?
     
  3. nappin_zz

    nappin_zz

    Joined:
    Nov 15, 2017
    Posts:
    42
    Hi, nope at the moment it doesn't. We are working on an update to include root motion as well
     
  4. GrooGadgets

    GrooGadgets

    Joined:
    Apr 2, 2009
    Posts:
    71
    Thanks for the reply, can you tell me when you expect the update to be ready?
     
  5. nappin_zz

    nappin_zz

    Joined:
    Nov 15, 2017
    Posts:
    42
    I've got no ETA at the moment as more important asset updates are taking priority. When I'll have an idea of the timeframe I'll of course update you!
     
    Last edited: Oct 27, 2022
  6. esgugel

    esgugel

    Joined:
    Jan 10, 2020
    Posts:
    1
    RuntimeNavMeshBuilder: Source mesh eyes does not allow read access. This will work in playmode in the editor but not in player
    UnityEngine.AI.NavMeshSurface:BuildNavMesh()
    NavMeshGenerator:Start() (at Assets/MyAssets/Scripts/NavMeshGenerator.cs:13)



    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.SceneManagement;
    5. using UnityEngine.AI;
    6.  
    7. public class NavMeshGenerator : MonoBehaviour
    8. {
    9.     public NavMeshSurface surface;
    10.  
    11.     void Start()
    12.     {
    13.         surface.BuildNavMesh();
    14.     }
    15.  
    16.     // Update is called once per frame
    17.     void Update()
    18.     {
    19.      
    20.  
    21.        // UpdateNAvmesh();
    22.     }
    23.  
    24.     public void UpdateNAvmesh()
    25.     {
    26.      
    27.     }
    28. }
    29.  
     

    Attached Files:

  7. nappin_zz

    nappin_zz

    Joined:
    Nov 15, 2017
    Posts:
    42
    Hi! As far as I can tell the code you are showing is about the navmeshes and doesn't have to do with the eyes mesh. The code is also not from the asset. What's the issue specifically?
     
  8. theflorist614

    theflorist614

    Joined:
    Jul 2, 2022
    Posts:
    6
    Hello, this asset is pretty much everything I need. However I am stumped on implementing a simple climbing mechanic similar to what you'd find in Breath of the Wild. Curious to know if anyone has any idea how you'd include something like that?
     
  9. nappin_zz

    nappin_zz

    Joined:
    Nov 15, 2017
    Posts:
    42
    Hi, if you intend to implement a climb mechanic I suggest to use the "Ladder" script and mute the CharacterManager script when on a wall or tweak its gravity / drag values. I'm of course available if you need help with custom code!
     
  10. Migaroez

    Migaroez

    Joined:
    Jun 16, 2014
    Posts:
    3
    Am I missing something or is the camera prefab shown in the documentation not included in the current release?

    Update
    There is indeed no prefab, but the object does exist in the sample scene which is in the top folder
     
    Last edited: Sep 19, 2022
  11. nappin_zz

    nappin_zz

    Joined:
    Nov 15, 2017
    Posts:
    42
    Hi Migaroez! The asset works with cinemachine but supports all kinds of custom camera solutions. In the example scene I've setup a cinemachine that can indeed be copied in your own controller but also you can create another cinemachine camera solution and plug it in the controller.

    If enough people ask for it, I'll create a few cinemachine camera prefabs for those that want to use this setup. Tnx for the feedback!
     
    Dervishes likes this.
  12. macube

    macube

    Joined:
    Jul 16, 2017
    Posts:
    37
    Hey,
    i'm tested the webgl demo from the asset and i noticed one thing: if you stand directly in front of a wall and press the jump button, the jump does not work. A bug?
     
  13. Gardan

    Gardan

    Joined:
    Jul 5, 2012
    Posts:
    3
    Hi, I've purchased the asset a few months ago, but only got the chance to use it recently. Loving it so far!

    Edit: I had a question regarding slopes, but it seems I didn't notice I just had to check the Lock on slope box to get the result I wanted.

    What I'm trying to achieve is to have the character slow down when going up a slide, and speed up when going down.
    I believe I have to tweak canSlideMultiplierCurve, and I got a moderate success in doing so, but I do have jittery movement, as both negative and positive values are applied during update.

    Code (CSharp):
    1. if (transform.position.y < lastCharacterYPosition){
    2.     Debug.Log("going down");
    3.     canSlideMultiplierCurve = 3.0f;
    4. }
    5. else if (transform.position.y > lastCharacterYPosition){
    6.     Debug.Log("going up");
    7.     canSlideMultiplierCurve = -1.0f;
    8. }
    9.  
    10. lastCharacterYPosition = transform.position.y;
    I'm not really sure if there is a proper and easy way to determine if the character is going up or down, as
    currentSurfaceAngle is always positive.
     
    Last edited: Nov 17, 2022
  14. GrooGadgets

    GrooGadgets

    Joined:
    Apr 2, 2009
    Posts:
    71
    Hey @nappin_zz any word on root motion support?
     
  15. nappin_zz

    nappin_zz

    Joined:
    Nov 15, 2017
    Posts:
    42
    Hey @Gardan! Awesome thank you for the kind words let me know if you encounter other issues!
     
  16. nappin_zz

    nappin_zz

    Joined:
    Nov 15, 2017
    Posts:
    42
    Hey @GrooGadgets, not yet other updated are taking priority as of now. When we work on it I'll be sure to ping you! Tnx
     
  17. Psycho-Designs

    Psycho-Designs

    Joined:
    Oct 9, 2013
    Posts:
    14
    Hi, Would this character controller be able to walk around a dynamic RigidBody platform? I saw in the documentation that it works but I'd have to freeze rotation and have the RigidBody controlled by the script. Would it be possible to have it work with a RigidBody that's driven by physics (Like Wheel Colliders)?
     
  18. Alima-Studios

    Alima-Studios

    Joined:
    Nov 12, 2014
    Posts:
    78
    Hi , speed of fall is damped when jumping
     
  19. blunzn

    blunzn

    Joined:
    Jan 14, 2015
    Posts:
    14
    hi, is this controlling a dynamic rigid body, so that physical interactions with other dynamic objects of different weights creates physically plausible results? Ie that lighter objects can be pushed more easily than heavier objects, and the player itself can be pushed by other moving entities? thanks!
     
  20. Yardood

    Yardood

    Joined:
    Mar 29, 2015
    Posts:
    7
    Hey, is there any easy way to implement a custom gravity code I have for this player? i'm having a walkable planets with custom directions to the gravity type of project.

    Thanks!
     
  21. Alima-Studios

    Alima-Studios

    Joined:
    Nov 12, 2014
    Posts:
    78

    not completly , I had to change some code , rotations are being setted directly in transform , this is not correct , must be using rigidbody
     
  22. AmazingRuss

    AmazingRuss

    Joined:
    May 25, 2008
    Posts:
    933
    Hi;

    I am having trouble figuring out how to make a character slide down a wall. If you jump at a wall while moving toward it, you will stick there until you move back. If you just let go of the keys, it slowly slides down the wall.

    I have set wall friction to 0.01.

    How can I make him slide down even if the forward key is held?
     
  23. Spikebor

    Spikebor

    Joined:
    May 30, 2019
    Posts:
    280
    Hi, How to move character with other character's body part?
    And furthermore, climb on other character's body

    https://youtube.com/shorts/Grxqx5imf9g?feature=share
    In this video I tried to put moving platform (which taken directly from the demo scene. but does not move, just be child of the Chest monster's head bone)
    The player character can only inherit rotation in one direction, why is that?

    I want to make game where character can climb on other.

    Wishlist for a feature that match behaviour of moving platform, but just for collider on character's body.
    This way we can climb huge beast, that will be lot of fun.
     
  24. nappin_zz

    nappin_zz

    Joined:
    Nov 15, 2017
    Posts:
    42
    Hi @blunzn! Yep the interactions are physically driven, so heavier objects would be more "difficult" to push then lighter ones. In the sample scenes there are a bunch of rigidbodies and cubes to experiment with it. If you have additional questions feel free to reach out via email!
     
  25. nappin_zz

    nappin_zz

    Joined:
    Nov 15, 2017
    Posts:
    42
    Hi @AmazingRuss! In the older version of the asset there was a naming error in the variable (it should be fixed in the most recent version of the asset, currently in submission). Instead of going for the minimum on the slider you should go for the maximum (0.99). Sorry for the inconvenience
     
  26. nappin_zz

    nappin_zz

    Joined:
    Nov 15, 2017
    Posts:
    42
    Hi Spikebor! The character can inherit the rotation on multiple directions

    timestamp 3:16

    It seems a bit unusual that the movement is not inherited, if you want feel free to reach out via email so that we can talk about your setup and find out what might be the problem!
     
  27. WryMim

    WryMim

    Joined:
    Mar 16, 2019
    Posts:
    69
    Is a discount planned and when?
     
  28. nappin_zz

    nappin_zz

    Joined:
    Nov 15, 2017
    Posts:
    42
    Hi @WryMim! Unfortunatelly publishers can add a discount to their asset only when they are launched, after that is the Unity Asset Store that decides what assets are sold with a discount and when
     
  29. umbrella-crash

    umbrella-crash

    Joined:
    Mar 3, 2022
    Posts:
    20
    My mouse-look behavior is much too sensitive (particularly in first person, which is what I'll be using). I haven't been able to find a setting for this. Also, I'm puzzled because this is not a problem in the WebGL demo. In any case, how can I make the mouse movement less twitchy?

    My setup: I've installed this asset in a fresh 2022.3.6 URP project with Cinemachine and Input System.

    Thank you for making an asset that is very well organized with parts that seem clear and decoupled!
     
  30. nappin_zz

    nappin_zz

    Joined:
    Nov 15, 2017
    Posts:
    42
    Hi, thank you very much I'm glad you are enjoying the asset!

    I believe we chatted about the topic via mail but just to inform everyone else reading: the camera system is completely separated from the core asset and it uses Cinemachine. If you want to tweak its behaviour / sensitivity / setup you can do it via cinemachine components. You can also plug your own custom camera solutions if you want. Anyway next update I'll include some premade camera setups just in case :)
     
  31. Yonkec

    Yonkec

    Joined:
    Jun 25, 2015
    Posts:
    2
    Sorry, I'm good. There was an issue w/ my Cinemachine install as best I can tell, once I removed and reinstalled that the problem was resolved.

    Love the controller!
     

    Attached Files:

    Last edited: Dec 18, 2023
  32. borgstation

    borgstation

    Joined:
    Jul 19, 2020
    Posts:
    19
    Hi! I'm having trouble getting the demo scene up and running nicely.
    It seems that either I'm not switching (enable/disable) from gamepad to mouse and keyboard correctly or it's not responding correctly to keypresses since jump/crouch won't work.
    Looks like others made it work but I think I'll need some help. :)
    I've set up a new project in birp with cinemachine 2.9.7 and input system 1.7.0.
    Got some missing scripts in thirdpersoncamera_mouseandkeyboard object
    upload_2023-12-19_9-59-40.png

    and in VFX object if any of those could be the cause
    upload_2023-12-19_10-1-17.png
     
  33. borgstation

    borgstation

    Joined:
    Jul 19, 2020
    Posts:
    19
    Probably found it. The ground mask was set to Nothing in the Character Manager script.
     
  34. nappin_zz

    nappin_zz

    Joined:
    Nov 15, 2017
    Posts:
    42
    Hello @borgstation! Unfortunately, when you download an asset from the asset store, you need to manually assign layers to the layer masks in the scripts, unless the asset uses pre-made layers like "Default" or "UI." The reason for this is that importing asset layers along with the asset could potentially disrupt your project.

    I'm glad to hear that you found a solution, feel free to reach out via email if you need help with custom code or anything else!
     
    borgstation likes this.
  35. UDN_388648da-a4c8-4308-af17-47614073dd10

    UDN_388648da-a4c8-4308-af17-47614073dd10

    Joined:
    May 13, 2017
    Posts:
    61
    The camera in the demo scene does not work.
    The character can be controlled, but it does not follow the character; the character disappears from the screen when it moves off the screen.

    When I press the M key, the SetCamera function in CameraManager.cs is called, but the camera does not move, whether the camera is in FPS or TPS.
    Please let me know the cause.
     
  36. NickNukem

    NickNukem

    Joined:
    May 11, 2020
    Posts:
    5
    I also have this issue. MainCamera is missing a script in the console log for the demo scene as well. Also trying to figure out how to get the character to work just assigning the MainCamera using old input system. All enable/disable steps have been done.
     
  37. NickNukem

    NickNukem

    Joined:
    May 11, 2020
    Posts:
    5
    Correction. All Cameras in demo scenes are missing scripts
     
  38. NickNukem

    NickNukem

    Joined:
    May 11, 2020
    Posts:
    5
    If you are using the old input system and need to get by for now with just using your MainCamera and/or PlayerCamera etc. Make sure it is NOT a child of your player game object and attach this script to the camera: (if you don't need the isCameraLocked state I have just remove it.

    ------------------------------------------------------------------------

    using UnityEngine;

    public class PlayerCamera : MonoBehaviour
    {
    [Header("Camera Control Settings")]
    [Tooltip("Sensitivity of mouse movement.")]
    public float mouseSensitivity = 100f;

    [Tooltip("Offset from the player's position to place the camera.")]
    public Vector3 cameraOffset = new Vector3(0f, 1f, 0f);

    [Header("Player Reference")]
    [Tooltip("Transform component of the player object.")]
    public Transform playerBody;

    [Header("Lock Settings")]
    [Tooltip("Lock or unlock the camera's rotation.")]
    public bool isCameraLocked = false;

    private float xRotation = 0f;
    private float yRotation = 0f;

    void Start()
    {
    Cursor.lockState = CursorLockMode.Locked;

    // Initialize camera's y rotation to align with the player's starting orientation
    yRotation = playerBody.eulerAngles.y;
    }

    void FixedUpdate()
    {
    if (!isCameraLocked)
    {
    HandleMouseMovement();
    }
    }

    private void LateUpdate()
    {
    FollowPlayer();
    }

    void HandleMouseMovement()
    {
    float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
    float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;

    // Calculate new pitch rotation (xRotation) for up and down camera movement
    xRotation -= mouseY;
    xRotation = Mathf.Clamp(xRotation, -90f, 90f);

    // Calculate new yaw rotation (yRotation) based on the mouse's X-axis movement
    yRotation += mouseX;

    // Apply calculated rotations to the camera
    transform.rotation = Quaternion.Euler(xRotation, yRotation, 0f);
    }

    void FollowPlayer()
    {
    // Update camera's position to follow the player with the specified offset
    transform.position = playerBody.position + cameraOffset;
    }

    public void SetCameraLock(bool isLocked)
    {
    isCameraLocked = isLocked;
    Cursor.lockState = isLocked ? CursorLockMode.Locked : CursorLockMode.None;
    }
    }

    -------------------------------------------------------------