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.

Character Controller Pro

Discussion in 'Assets and Asset Store' started by lightbug14, Jan 15, 2020.

  1. justbake

    justbake

    Joined:
    Feb 20, 2018
    Posts:
    1
    Is it possible to use this as a top down 2d controller?
     
  2. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    376
    Hi, thank you very much!

    "Grab it" allows you to filter those rigid bodies via a layer mask. Unfortunately, there is no per-object filter available. Implementing this filter should be really simple.
    1. Define a List inside GrabIt.cs
    Code (CSharp):
    1. public List<Transform> ignoredTransforms = new List<Transform>();
    2. Add the following if statement (find "Input.GetMouseButtonDown(0)"):
    Code (CSharp):
    1.               if (Input.GetMouseButtonDown(0))
    2.                 {
    3.                     RaycastHit hitInfo;
    4.                     if (Physics.Raycast(m_transform.position, m_transform.forward, out hitInfo, m_grabMaxDistance, m_collisionMask))
    5.                     {
    6.                    
    7.                         if (!ignoredTransforms.Contains(hitInfo.transform))  //<------------
    8.                         {
    9.                             Rigidbody rb = hitInfo.collider.GetComponent<Rigidbody>();
    10.                             if (rb != null)
    11.                             {
    12.                                 Set(rb, hitInfo.distance);
    13.                                 m_grabbing = true;
    14.                             }
    15.                         }
    16.                     }
    17.                 }
    The rest should be simple, create a MonoBehaviour and keep that list updated with the current ground rigidbody.
    Code (CSharp):
    1. public GrabIt grabIt = null;
    2.  
    3. void FixedUpdate()
    4. {
    5.       if (CharacterActor.isStable)
    6.       {
    7.             grabIt.ignoredTransforms.Clear();  //i'm just clearing everything, probably not the best solution but it will work
    8.             grabIt.ignoredTransforms.Add(CharacterActor.GroundTransform);
    9.        }
    10. }
    I'll update this asset with this small addition and some more.

    Have you tried to change the "Human input type" to Custom (Camera3D)?

    Yes, Camera3D uses its own "input handler".
     
    Last edited: Oct 13, 2021
  3. Broudy001

    Broudy001

    Joined:
    Feb 12, 2020
    Posts:
    62
    @lightbug14 I updated to 1.3.8 last night, and I'm now seeing a jitter in my character, most obviously in the arms. I was previously using 1.3.6 and not seeing the same thing.

    Has anything changed that might affect this?
     
  4. orangataketo

    orangataketo

    Joined:
    May 14, 2017
    Posts:
    3
    @lightbug14 How I can change the falling velocity (speed towards Y-axis) of a character?
    Does Character Controller Pro provide any parameter for this?
     
  5. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    376
    Not really (a null reference bug fix and one small velocity change(not grounded movement)). Interpolation stuff remains the same.
    Does this happen all the time? Any extra detail would help.

    Gravity-based movement is implemented like this:
    Velocity += down * gravity * deltaTime

    The component responsible for this is NormalMovement (Demo component). You can change the gravity value using the inspector.
     
    Last edited: Oct 20, 2021
  6. orangataketo

    orangataketo

    Joined:
    May 14, 2017
    Posts:
    3
    Thank you for your reply.
    I have found "Vertical Movement Parameters" in the "Normal Movement" class.
    Unchecking the "Auto Calculate" and changing the "Gravity" parameter did what I wanted.
     
  7. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    376
    I forgot to mention (@RafaelGuimaraesBarbosa and @bunnybreaker ), the Rigidbody null reference was caused by the Collider.attachedRigidbody property. This property gets null if the object (platform) is inactive. The documentation says: "Returns null if the collider is attached to no rigidbody.". You'd expect to be able to get that rigidbody reference, however, it seems the system "disconnects" the rigidbody from the collider everytime the object gets inactive.
     
  8. GrandBOOM

    GrandBOOM

    Joined:
    Oct 25, 2016
    Posts:
    21
    Hey, I am wondering if you enforce license requirements for this Character controller in such a way as to

    a) require all persons with access to source code to have a license

    b) require only people who work on a project daily to have a license

    c) require only people who actually change the values on the Character Controller (not Sound Designers, QA personnel etc...) to have a license.

    d) only one license is required per project

    Thank you for your time.
     
  9. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    376
    Hi,
    Thanks for the interest in the asset!

    If you want to know exactly how things work, please read the asset store EULA (they make the rules). In any case, I would highly recommend you to contact support if you want precise information about this.

    Depending on the asset category (scripting, editor extension, 3d models, etc), some assets will fall under one particular license type (for more info please read this https://assetstore.unity.com/browse/eula-faq). Scripting assets (like this one) belong to the "per seat" category (it is a "tool"). Technically speaking, this means all n members from your team (whether they are independet devs or part of a business/company) are going to need n (per-seat) licenses if they're going to use the asset.


    From the FAQ:
    - Per seat means that use is exclusive to the named user assigned to that seat. In the case of an individual END-USER, the named user is that individual; if END-USER is a company or any other business, each seat license must be assigned to, and may be used exclusively only by, one (1) specific individual employee of that company or other business.

    - If an asset is NOT categorized as“Editor Extension”, “Scripting”, or “Services” and the END-USER purchaser of the license is a company or other business, then it can be shared with any employee within that company or business.

    - A contractor is a third party and as such a separate license would be required, except where the multi-entity license option is chosen. In that case, the contractor does not need a separate license as long as work is limited to the project for which the contractor was hired.

    ----------------------------------------------------------------------------------------------
    To the questions:

    To be honest i don't know the exact answer to that. Based on the EULA, any user that's going to "use" the asset needs to have a seat.
    (From the FAQ)
    Q: What does “use” mean for per seat licenses? Does anyone who
    would have even only passive access to a project require a seat license?

    A: This means any use that requires a license under applicable law. Unfortunately, Unity is not a law firm and cannot provide legal advice. If you are unsure if your specific case is one for which use would require a license, we suggest that you consult appropriate legal counsel. As an example in cases where Unity is the Provider and licensor of an asset, we can say that we, as licensor, do not consider only passive access to a shared repository as requiring a license.


    AFAIK, seats are not tied to specific projects.

    Personally, i don't care that much, get one license and shared that with your team. If you want to play by the rules, please contact support, they will tell you exactly how to proceed.
     
    GrandBOOM likes this.
  10. Ceraph

    Ceraph

    Joined:
    May 16, 2013
    Posts:
    19
    Hello,

    I'm trying to implement a movement scheme for my game using this asset pack that controls similarly to World of Warcraft. The camera will always stick behind the player. The player can press the W key to move forward, the S key to walk backwards without turning the camera, and the A and D keys rotate the character left and right.

    So far I'm most of the way there but I'm having some issues in some key places. I'm using version 1.3.7.

    1) I have a Cinemachine camera that follows behind the player and I use it for the movement reference in NormalMovement, so W always moves forward and A and D rotate the character left and right. I'm not sure how to control the speed at which the character rotates, though. I tried changing the rotation lerp speed in graphics root controller but that just makes rotation feel slippery and laggy. Ideally I'd like to be able to define a separate speed for Y axis input (forward / backward movement) and X axis input (rotation).

    2) Right now pressing the S key will start spinning the character around instead of walking backwards. I've been working in the code base for a while now but I'm still not entirely sure how to go about tackling this change.

    Any help you could provide on these two issues would be greatly appreciated!

    Thanks,
    Ceraph
     
  11. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    376
    Hi @Ceraph

    This solution is 100% based on the demo stuff (Camera3D and NormalMovement):
    1. Use NormalMovement --> Select LookingDirectionParameters -> LookingDirectionMode = ExternalReference
    2. Use the Camera script as the rotation source (a.k.a the camera will rotate the character).
    3. Use the ExternalReference as your movement reference (CharacterStateController component)
    If you test this, the character will do what you want, however, you will need to move your mouse (by default) to get that rotation. The Camera3D script is using (by default = Unity's old input manager) "Camera X" and "Camera Y" as input axes. Here is the trick, go to Project Settings/Input Manager and modify Camera X from "Mouse Movement" to "Key or Mouse Button", then select A and D as the buttons.

    I mention this because I don't know if you are willing to mess around with the code (create your own stuff, which i highly recommend). Personally, i don't like having the camera code in charge of the character rotation. Since you are using CM for camera logic, a "better" solution will be:
    1. Forget about the external reference/camera. Go to the CharacterStateController component and change your movement reference to "Character" (or "World"). The reason for this is that you don't need to be constantly calculating your forward movement direction (when you press W) based on the camera. The forward direction should always be the character "Forward" vector.
    2. I'm assuming the character will be the one in control. The camera should only follow the character (behind it). I believe you can do this with CM right now (Camera3D cannot do this, although the solution is easy).
    3. Create your rotation logic (you can extend NormalMovement or create a new state if you want). Here is the basic theory:
    Code (CSharp):
    1. // Detect A/D keys, and then convert that into a deltaAngle
    2. //A and D keys are represented (by default) by the movement action (x component).
    3. float deltaAngle = rotationSpeed * dt * CharacterActions.movement.value.x;
    4.  
    5. // Smooth the angle value using a lerp (optional)
    6. float lerpedDeltaAngle = Mathf.Lerp(0f, deltaAngle, someValue * dt );
    7.  
    8. // Use SetYaw to rotate the character
    9. if(lerpedDeltaAngle!= 0f)
    10.         CharacterActor.SetYaw(lerpedDeltaAngle);
    11.  
    You need to use that deltaAngle for the yaw rotation. Here is a function (from CharacterActor) that does that:
    Code (CSharp):
    1. public void SetYaw(float angle)
    2. {
    3.       Forward = Quaternion.AngleAxis(angle, Up) * Forward;
    4. }
    4. Create your movement code (you can reuse ProcessPlanarMovement from NormalMovement). The key is to change ProcessPlanarMovement's targetPlanarVelocity (you have three of them):
    Code (CSharp):
    1. targetPlanarVelocity = CustomUtilities.Multiply(CharacterActions.movement.value.y * CharacterActor.Forward, currentPlanarSpeedLimit, speedMultiplier);
    The first argument (the only thing i have changed) indicates that velocity will be defined by W/S keys (CharacterActions.movement.value.y... -1,0 or 1) multiplied by the Forward direction. I'm basically ignoring A/D-based movement.



    That's normal, when you press S the character turns around (180 degrees), then the camera goes behind it, and the cycle repeats.
     
  12. Ceraph

    Ceraph

    Joined:
    May 16, 2013
    Posts:
    19
    Your first solution worked like a charm, thank you! I have a deadline I need to hit so unfortunately the quick and easy answer will have to do for now, but I definitely agree that character movement should not be controlled by the camera. I will have to come back and implement your second solution when I have more time.

    A nice added bonus of using the first solution is that it also causes the character to backpedal when pressing the S key because of the external movement reference.

    Thank you again,
    Ceraph
     
    lightbug14 likes this.
  13. victorkin11

    victorkin11

    Joined:
    Apr 20, 2013
    Posts:
    175
    I only use CharacterActor & character body, I have trouble about the Step Up Distance, if it is too small, let say 0.3-0.4, if I stand close to the stair before go up, It will easily stuff in the stair and not going up, if I set it to 0.5, then the actor just will cross all the fence even it can go up to stair normally. (When I using unity character controller, it can nicely to go up the stair but not cross the fence.)


     
    Last edited: Nov 6, 2021
  14. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    389
    It would be amazing to get Mirror support on this
     
  15. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    389
    Yeah I would really love to be able to use this with Mirror,

    Any pointers on which scripts will have to be modified to do so?

    I would like to give it a try.



    - I've tried by modifying the CharacterBrain by adding Using Mirror;
    changing it to a NetworkBehaviour, and changing its brain stuff within FixedUpdate and Update to have
    if (!isLocalPlayer) return;
    // This way the player can only control its own character

    I had to move the CharacterBrain comoponent to the parent of the Character Obj due to the network identity that must go with it, (It has to be on the root parent obj)

    as a result I changed the CharacterStateController to:

    // CharacterBrain = this.GetComponentInBranch<CharacterActor, CharacterBrain>();
    CharacterBrain = this.GetComponentInParent<CharacterBrain>();

    It seems that this way the players are controlled individually however they are not synchronizing between the networks,

    I also tried it without CharacterBrain and a simple script to move the CA by;
    if (!isLocalPlayer) return;
    if (Input.GetKey(KeyCode.W))
    {
    characterActor.Position += new Vector3(0, 0, _speed * Time.deltaTime);
    }


    Any pointers on how to make this work, would be much appreciated.

    Thank you
     
    Last edited: Nov 9, 2021
  16. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    389
    Follow up after many tests,

    The moment I add the CharacterActor and Body the player no longer syncs across.

    Looking forward to your pointers and further help on this,

    Note: I am also using Smooth Sync asset for a better sync with rigidbody sync capabilities

    Thank you
     
  17. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    376
    Sorry for the delay, my SSD unexpectedly died:(, so i won't be able to use Unity for at least two days.

    @victorkin11
    Question, Why is there a ramp on top of the stairs model? Are those objects (ramp and stair) included in the stable layer mask (CharacterActor inspector)?

    It is not recommended to modify Core/Implementation components. The best you can do is enable/disable the Brain (like a regular MonoBehaviour) from an external script. For example:
    Code (CSharp):
    1. public CharacterBrain brain;
    2.  
    3. ...
    4. void Awake()
    5. {
    6.        brain.enabled = isLocal;
    7. }
    8.  
    9.  
    GetComponentInBranch should find the component by using in this case the CharacterActor's gameObject as the root (first type parameter). Could you describe your character hierarchy (root, childA, childB, etc)?
     
  18. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    389
    I am using the Demo Character 3D

    upload_2021-11-11_8-15-43.png

    Okay I re-imported the Asset to clear out any modifications made,

    I added this script to the root of the Demo Char 3D:

    on Start()
    if (!(hasAuthority || (NetworkServer.active && netIdentity.connectionToClient == null)))
    brain.enabled = false;

    for whatever reason if I do isPlayerLocal it is always false so the code above worked good. Each player has their own character control,

    I still can't figure out how to sync them between clients, I've tried it with NetworkTransform, and SmoothSync,


    Using the NetworkRigidbody does sync it partially, its very jittery unless I spam press the WASD, then its more smooth. It seems like it only syncs once WASD is pressed?

    The Network Rigidbody is supposed to be used in conjunction with Network Transform as the NetworkRigidbody handles RB velocity, but the NetworkTransform handles the actual position.

    However seems like the Network Transform is having issues with this character controller to properly sync it.
     
    Last edited: Nov 11, 2021
  19. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    389
    I'm closer to figuring this out,

    However running into issues as I have to Spawn the 3D Camera during runtime and cannot figure out how to set the "MovementReferenceMode" to external,

    playerCamera.GetComponent<Camera3D>().targetTransform = _graphics.transform;
    _characterStateController.MovementReferenceParameters.externalReference = _PlayerCamera.transform;
    _characterStateController.MovementReferenceParameters.movementReferenceMode = MovementReferenceMode.External; ???

    Can you please help with this code and anything else I may need to do to make it work with the 3D camera spawned during runtime

    Thank you
     
    Last edited: Nov 13, 2021
  20. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    376
    That's good.

    Mirror doesn't sync the body constantly unless velocity is higher than some threshold.
    From the documentation:
    The Sensitivity options allow you to set a minimum thresholds before values are send over network. This helps minimize network traffic for very small changes.

    In theory, you need to assign a NetworkIdentity, a NetworkTransform and a NetworkRigidbody. I believe Mirror is also checking for velocity/angular velocity errors in order to properly sync the bodies, this is why a NetworkRigidbody is required.
    From the docs:
    Network Rigidbody works best when there is also a NetworkTransform for the object to keep position as well as velocity in sync.

    In any case, i would recommend to sync vanilla rigidbodies first (i don't know if you've already done this). Regarding networking, there are tricks you can do (especially with rigidbodies). For example, this is from the creator (github):
    ...I recommend using NetworkTransform and setting rigidbody to kinematic=!isLocalPlayer so only local player uses rigidbody, others just apply the transform position/rotation...
    Which is a clever trick, the server knows about velocities, positions and rotations, so using kinematic RB for non-local clients could work. This can be also bad, especially if you need to collide with other characters (kinematic means infinite mass).

    CharacterStateController's MovementReferenceMode is a public property:
    Code (CSharp):
    1. public MovementReferenceParameters.MovementReferenceMode MovementReferenceMode
    2. {
    3.       get => movementReferenceParameters.movementReferenceMode;
    4.       set => movementReferenceParameters.movementReferenceMode = value;
    5. }
    6.  
    First, you need a reference to CharacterStateController in order to use the property.

    Set the mode to external, and then use the ExternalReference (another property) to set up the camera transform as your reference.
     
  21. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    389
    Okay i was missing:
    using static Lightbug.CharacterControllerPro.Implementation.MovementReferenceParameters;
    in order to
    _characterStateController.MovementReferenceParameters.movementReferenceMode = MovementReferenceMode.External;
     
  22. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    389
    Is it possible to add a Camera that follows the player from behind, and with the option to press the "Free Cam" button to look around with the mouse? As well as include the free look on the current 3D Camera
     
  23. abandon_games

    abandon_games

    Joined:
    Sep 1, 2017
    Posts:
    33
    Hi Lightbug!

    First of all, thank you for an awesome asset and the attention and love that you give it!

    I apologize if this was answered previously in the thread or documentation but I did not see it specifically called out:

    What's the proper way to completely disable and re-enable player control of their character in first person mode?

    Example:
    1. the player character (in first person mode) walks into a trigger
    2. the trigger disables all player control (body and head)
    3. a custom script moves and rotates the player's character to a particular destination
    4. all player control is re-enabled
    What is the proper way to accomplish step 2 and 4 above?

    I currently have something like this, which seems to get the job done, but I have seen some unexpected behavior so I'm wondering if there's a better way to do it:

    Code (CSharp):
    1. public void DisablePlayerController()
    2. {
    3.   CharacterActor actor = gameObject.GetComponent<CharacterActor>();
    4.   CharacterBrain brain = gameObject.GetComponentInChildren<CharacterBrain>();
    5.   Camera3D headController = gameObject.GetComponentInChildren<Camera3D>();
    6.  
    7.   actor.enabled = false;
    8.   brain.enabled = false;
    9.   headController.enabled = false;
    10. }
    And then...

    Code (CSharp):
    1. public void EnablePlayerController()
    2. {
    3.   CharacterActor actor = gameObject.GetComponent<CharacterActor>();
    4.   CharacterBrain brain = gameObject.GetComponentInChildren<CharacterBrain>();
    5.   Camera3D headController = gameObject.GetComponentInChildren<Camera3D>();
    6.  
    7.   actor.enabled = true;
    8.   brain.enabled = true;
    9.   headController.enabled = true;
    10. }
    Thanks!!
     
  24. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    389
    I have to set the Animator Controller via NetworkAnimator or store all the controller in a list and send a RPC with the index to set it locally,

    What is the best way to do this, and where? Do I have to change the CharacterStateController.cs or?

    I was thinking maybe change the Animator to NetworkAnimator but that may complicate the rest of the scripts and need to be modified. Please let me know


    #2 When I have the Run to toggle instead of hold, the crouch will not work even if the player is stationary, unless Run is toggle to off, any chance the player can still crouch just at a slower speed while in Run mode?

    Thank you
     
    Last edited: Nov 15, 2021
  25. rojbarak

    rojbarak

    Joined:
    Nov 17, 2021
    Posts:
    16
    Hi,

    Having issues with Unity InputSystem. Is there an input action asset in this package or am i missing something? Using a preset was quite useful for legacy inputs but new system's implementation is not that easy.
     
  26. Rallix

    Rallix

    Joined:
    Mar 17, 2016
    Posts:
    139
    Maybe this page will help. It contains an InputHandler script and two input action assets to download.

    ---

    But I was actually also going to ask about the new input system. I did a clean reimport of the asset, added the new input handler script, but I'm having a problem with the actual Movement ("HorizontalAxis", "VerticalAxis"). In the demo scene, jumping works fine, but the character doesn't move.

    upload_2021-11-17_18-30-1.png

    The values are displayed on the brain component, but somehow they're not propagated to the animator (NormalMovement). My setup was adding the input action assets to the clean import, setting the player's and camera's input handler to Custom and linking the respective assets. Am I missing a step in the process, or is there something else to look for?

    (Double)jumping – fine:
    upload_2021-11-17_18-38-11.png

    Moving – something wrong
    upload_2021-11-17_18-39-37.png
     
  27. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    376
    It is possible, although adding a free look to the existing Camera3D sounds a little off to me. I prefer to add a "Fly mode" (half life style) to the whole character.


    Do you mean the Animator component, or a Runtime Animator Controller?


    Yes, check NormalMovement.cs:
    Code (CSharp):
    1. if (wantToCrouch || !planarMovementParameters.canRun)
    2.      wantToRun = false;
    Remove the "wantToCrouch" condition.
     
  28. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    376
    Thank you!

    2) You can disable anything you want. For example:
    Body:
    - CharacterBrain = inputs won't work.
    - CharacterActor = stable/unstable features won't work, however, the rigidbody will be active.
    - CharacterStateController = No FixedUpdate (= States won't be updated).
    - Additionally, you can set the actor as Kinematic.
    Head:
    - Camera3D handles the head, disable it.

    4) Is exactly the oppositve.



    You are doing things right. One question: When you say "the character doesn't move", Do you mean velocity = zero? I'm asking because you also mentioned the Animator.
     
  29. Rallix

    Rallix

    Joined:
    Mar 17, 2016
    Posts:
    139
    Yes, sorry, no velocity. As if the keypresses didn't do anything (but jumping, dashing works and the Movement axes are displayed correctly in the CharacterBrain's inspector). I didn't debug how the values are propagated through the code and checked just the animator, where I noticed HorizontalAxis & VerticalAxis parameters are not being set.

    Here's an example gif:
    Velocity.gif
     
  30. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    389
    Any pointers on how I can create an additional Camera3D that has that option to toggle on/off pitch/yaw look, and to revert back to its default start settings? ( I was thinking even just a toggle button to true/false pitch/yaw, but not sure on having it revert to a specific pitch yaw when toggle off

    For the animator i am almost there... this is what I have so far - included within the CharacterStateController script

    public NetworkAnimator _networkAnimator = null;
    public List<RuntimeAnimatorController> _animationControllers = new List<RuntimeAnimatorController>();
    private int GetIndexFromAnimatorController(RuntimeAnimatorController controller) => _animationControllers.IndexOf(controller);

    in fixed update where it changed the animator controller:

    if (CanCurrentStateOverrideAnimatorController)
    {
    // Original Animator.runtimeAnimatorController = CurrentState.RuntimeAnimatorController;
    SetControllerOverNetwork(CurrentState.RuntimeAnimatorController);
    }

    //called on owner.
    private void SetControllerOverNetwork(RuntimeAnimatorController controller)
    {
    int index = GetIndexFromAnimatorController(controller);
    SetControllerFromIndex(index);
    ServerSetController(index);
    }

    private void SetControllerFromIndex(int index)
    {
    _networkAnimator.SetController(_animationControllers[index]);
    }

    [ServerRpc]
    private void ServerSetController(int index)
    {
    SetControllerFromIndex(index);
    ObserversSetController(index);
    }


    The tricky part seems to be by not doing: Animator.runtimeAnimatorController = CurrentState.RuntimeAnimatorController;

    I get some warnings:

    Parameter 'Hash 940218630' does not exist.

    Parameter 'Hash 940218630' does not exist.

    Parameter 'Hash 896885292' does not exist.

    From the client to server, any idea what I am missing here?

    I changed the
    if (wantToCrouch || !planarMovementParameters.canRun)
    to -> if (!planarMovementParameters.canRun)

    But it still cannot crouch while running is toggle on
     
  31. rojbarak

    rojbarak

    Joined:
    Nov 17, 2021
    Posts:
    16
    Tnx. I already found the page and implemented InputSystem with given action assets. But still need to modify Demo Scene Manager(this one still has legacy inputs). Dev just skipped that one. And can't modify that script because I can't import InputSystem lib into that script (because of assembly def?). Anyways just disabled.
     
  32. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    389
    Can you help me with a script, I have a projectile that hits the player and on impact I want to have an exploding force to the player as well as the "Ice" effect for the next 3 seconds, so the player gets knocked the projectile's direction and slides
     
  33. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    376
    Sorry for the late reply!
    Thanks for the gif, at least the "movement" action is recognized by the brain (which means the input action asset is correct). Based on that gif, my guess is that your "Input movement reference" is returning nothing (Vector2.zero) when you press WASD. This reference combines input ("movement" action in this case) + "movement reference" (world/character or external mode) in order to produce a final direction. You can find the code for this inside CharacterStateController/MovementReference.

    Try this:
    1 - Go to the inspector (window) and choose Debug view.
    2 - Select the "States" game object (the one containing CharacterStateController).
    3 - Press Play (Minimized view), move your character using WASD.
    4 - Check if the InputMovementReference property (now visible in the inspector) changes ... it should.

    upload_2021-11-21_13-5-20.png

    The entire demo was built on top of the old input system. If you don't want to modify anything, use "both" (Project Settings/Player/Other settings/Active input Handling) input systems at the same time.
     
    Last edited: Nov 22, 2021
    rojbarak likes this.
  34. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    376
    Sorry, I forgot about the toggle part *facepalm*. If you remove the entire if statement, your character will be able to run (toggle) and crouch.


    i have no clue :(
     
  35. odk-mmmm

    odk-mmmm

    Joined:
    May 24, 2017
    Posts:
    3
  36. rojbarak

    rojbarak

    Joined:
    Nov 17, 2021
    Posts:
    16
    Ok that's not a big deal.
     
  37. Rallix

    Rallix

    Joined:
    Mar 17, 2016
    Posts:
    139
    Yes, you are right. Nothing in Input Movement Reference.

    upload_2021-11-22_18-16-34.png

    Based on what I can see, it sets the CharacterActions/movement correctly…
    upload_2021-11-22_18-18-27.png
    Goes up to the CharacterBrain and it actually sets the Input Movement Reference...
    upload_2021-11-22_18-29-24.png
    …but presumably, it's then overridden by something slightly later. Or the fact it was set this time might have something to do with this window-out-of-focus behaviour I noticed while I was debugging it:

    When I clicked around and pressed keys to make the window go out of focus, the character suddenly got stuck in one fixed direction (relative to the camera rotation) but started moving.
    Window Focus.gif
    It shouldn't be just my custom character setup, the same happens with the demo character scene well.
    Default.gif

    Any idea as to what could be happening? Thank you for your help!
     
  38. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    389
    Maybe I am doing something wrong?

    #1 When I remove the:

    1. if (wantToCrouch || !planarMovementParameters.canRun)
    2. wantToRun = false;

    Still cannot crouch while running is toggled on?


    #2 Can you help me with a script, I have a projectile that hits the player and on impact I want to have an exploding force to the player as well as the "Ice" effect for the next 3 seconds, so the player gets knocked the projectile's direction and slides
     
  39. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    376
    At least the character is moving, so "Movement" (the action) is there doing its thing. It seems like the input system is not updating inputs when you go out of focus (?). Movement (the action) doesn't change at all after that. Therefore, the character keeps using an old value, this is why it doesn't stop.

    At this point, you could try any of the following suggestions:
    - In play mode, press WASD, then go out of focus. After that, check the CharacterBrain inspector (in normal mode, not debug). If "movement" doesn't change, this has to be related to the input system in some way.
    - Which version of the Input system are you using? Could you update to a newer version? Or maybe go back to an older one? I'm using 1.2.0.
    - I've noticed that you are using Unity 2021 (based on the "play focused" button). Could this be due to some bug related to the editor? I know, a bug ... Unity .... crazy right?:D Check in the forum, maybe someone else is getting similar results.
    - Alternatively, you could go back to the old input system, just to confirm that things work as they should. The same thing i said to rojbarak, use both system at the same time (just for now).

    Or maybe, this is a CCP bug :( In any case, first i need to know that your input system is healthy.
    If this problem persists, please reimport everything again (delete CCP, and then click import).
     
  40. amoee

    amoee

    Joined:
    Jan 11, 2014
    Posts:
    10
    How do I set the control mode to 2.5D use NormalMovement ? help me
     
  41. rojbarak

    rojbarak

    Joined:
    Nov 17, 2021
    Posts:
    16
    Hi @lightbug14

    Can you help me about these or maybe you can lead me to the right direction.

    I have three issues:
    1.
    When character jumps on moving vehicle (moves in fixed update), vertical movement is not smooth and goes up and down like a stutter.
    2. When character lands, its sliding. Because vehicle changing velocity and also we have the vehicle velocity when we left it. So it is lerping that velocity to zero when it lands, but couldn't find it in codes.
    3. Capsule collider goes into vehicles front. Vehicle has exactly same convex collider but when it goes around 20m/s, player capsule sink into its front (not sinking when going 5m/s).

    All of the issues can be seen in this clip (ccp 1.3.8 & unity 2021.1)



    Also InterpolateActor is disabled (it also causes a lot of stutter, like camera update/fixed update type stutter).

    Thank you.
     
  42. Rallix

    Rallix

    Joined:
    Mar 17, 2016
    Posts:
    139
    Thanks for the suggestions! I did this entirely in a new 2021.2.2f1 test project to be sure none of my other assets/scripts is interfering.
    – When going out of focus, the "Movement" in CharacterBrain's Inspector resets back to (0,0), even though the character might continue moving.
    – I was using Input System 1.1.1, the (seemingly) last available version. Version 1.2.0 wasn't shown in the list even with experimental packages enabled, however, I could still add it manually ("Add package by name…"), even though it shows me a message that version wasn't verified for the Unity version I use.

    upload_2021-11-29_10-9-25.png

    And lo and behold, that fixed it, and the system now works as expected. So it was most likely a bug with the input system package. :)

    I was also going to ask what can I do about my character constantly crouching (as you can see in the gifs I posted previously), but that's probably caused by his short height (1.38m) when the animation blend tree has 1.425m for crouching. I don't know if it's the best approach, but I lowered all the "Pos Y" values proportionally and it seems fixed as far as I can tell.

    Thanks for all your help!
     

    Attached Files:

    Last edited: Nov 29, 2021
    lightbug14 likes this.
  43. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    573
    @lightbug14
    If I use 2D mode and I would like to orient my character graphics to the slope of the terrain (align z-rotation with slope angle), is this possible already or do I need to implement myself?

    I don't want/need to rotate the collider / rigidbody, I just want to rotate the graphics visually to align with the slope of the terrain.

    Thanks!
     
  44. Tenzho

    Tenzho

    Joined:
    Feb 15, 2015
    Posts:
    3
    Hi @lightbug14 ,

    Could you help me on a platform like an elevator which will only move upon activation. I have looked thru the demo scenes and only found platforms which are moving in a loop. Is there a way to only make the platform move upon calling its function, and move back to the same position when calling its function again?
     
  45. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    376
    Oh sorry! I totally missed that :(

    You are right, i forgot to mention the HandleSize method the other day.
    Go there and remove these lines:
    Code (CSharp):
    1. if (CharacterActor.IsGrounded && wantToRun)
    2.                 wantToCrouch = false;
    1. Detect the projectile. You have many ways to do this, for example:
    * use OnCollisionEnter (like with any monobehaviour)
    * Create a dedicated CharacterDetector (script)
    * loop over the current contacts (CharacterActor.Contacts)
    2. Apply force. You can use CharacterActor.RigidbodyComponent.AddForce (or AddExplosiveForce). This will modify the rigidbody velocity.
    3. Implement the effect. First of all, faking an ice material sounds wrong to me, it can be a bit too much. In my opinion, the best way to handle this is to modify planar movement (speed, acceleration/deceleration) directly. For example, while your character is being affected by a projectile (e.g. knockback effect) you can reduce the deceleration parameters. Or better yet, you can set up an entire new state.
    I would highly recommend you to create your own "knock back state". This also means coding your transitions as well (a couple of extra lines here and there).
     
  46. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    376
    Do you mean constraining the body position to a plane (e.g. XY plane)?
    Handling 2.5D is something i want to add to the controller. If you want perfect results, this must be done from by the actor.

    For now, you could find the closest point character-2.5DPlane (e.g. XY plane) and re-define velocity based on that.
    For the closest point you can use this.
    You can "guess" where the character is going to be (this is not exact of course) at the end of the frame.
    Code (CSharp):
    1. targetPos = currentPos + Velocity + deltaTime
    Based on that, you can modify the final velocity in order to constraint the character to the plane. For example:
    Code (CSharp):
    1. constraintVelocity = (closestPointOnPlane(targetPos) - targetPos) / deltaTime;
    Please note that this is pseudocode.

    You should apply this concept at the end of the NormalMovement logic
    Code (CSharp):
    1. protected virtual void HandleVelocity(float dt)
    2. {
    3.         ProcessVerticalMovement(dt);
    4.         ProcessPlanarMovement(dt);
    5.  
    6.         // <--- here
    7. }
    Or, if your state derives from NormalMovement, you can override HandleVelocity like this:
    Code (CSharp):
    1. public class NormalMovement2Dot5DVersion : NormalMovement
    2. {
    3.             protected override void HandleVelocity(float dt)
    4.             {
    5.                     base.HandleVelocity(dt);
    6.  
    7.                     // <---- Work here
    8.             }
    9. }
    As an alternative, you can create two invisible boxes :cool: and use the layer system in order to constrain the character position.
     
    Last edited: Nov 30, 2021
  47. amoee

    amoee

    Joined:
    Jan 11, 2014
    Posts:
    10
    thank you
     
    lightbug14 likes this.
  48. rojbarak

    rojbarak

    Joined:
    Nov 17, 2021
    Posts:
    16
    Ok #1 is gone when I removed GraphicsRootController. But other two still exist.
     
  49. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    376
    Hi,
    Apologies in advance, my internet connection has been very unpredictable recently.

    That stutter is expected in a way. The camera follows the "Graphics" transform, which is being interpolated at runtime. Like you said, the graphics root controller is responsible for that. I'm only seeing the stutter with the (wireframe) capsule.

    That happens because the character can support a "max ground velocity change" (see the inspector). Try to increase the "max ground velocity change" value.
    When your character lands on the vehicle (frame i), the ground velocity is vehicleSpeed, so the change is basically vehicleSpeed - 0. If your character doesn't support that change, it will lose contact with the vehicle. For subsequent frames (i+1, i+2, etc) this difference is reduced, this is why the character is able to stick to the vehicle perfectly.


    You using a <1,1,1> scale for the character, right? Step up distance value? This looks like a physics query (sphereCast) problem, probably coming from the ground check. I'll check that. I'm assuming that "convex" toggle is on.
     
    Last edited: Dec 1, 2021
  50. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    376
    Good news :), thanks for reporting this. Recently, i've received an email reporting the exact same problem.

    You are right, the animator controller from the demo is prepared for that specific character.
     
    Rallix likes this.
unityunity