Search Unity

  1. Unity 2019.4 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  3. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

▓▓▓▓▓▒▒▒▒▒░░░░░ Character Controller Pro (1.0.5) ░░░░░▒▒▒▒▒▓▓▓▓▓

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

  1. ikemen_blueD

    ikemen_blueD

    Joined:
    Jan 19, 2013
    Posts:
    316
    @lightbug14 Thanks for the clearer explanation about the External Velocity, I kind of get it now. Another quick question, can the actor controller get hits from some objects in a specific layer only, with Physic simulation ON, External Velocity ON? Or, do I have to set External Velocity OFF, use "Contact Rigidbodies tag" to collect Collision response contact (like version 1.0.x)?
     
  2. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    126
    Hi, to be honest i don't think there is a way to filter the collisions like that (using the physics API or something), i might be wrong. In that case it would be better to disable externalVelocity and use you own collision response.

    The "Contact Rigidbodies" tag was previously used by the CharacterActor. These contacts were coming from dynamic riigidbodies, using the tag "contactRigidbodies" tag, and the flag "firstContact".

    Code (CSharp):
    1. for( int i = 0 ; i < Contacts.Count ; i++ )
    2.         {
    3.             Contact contact = Contacts[i];
    4.  
    5.             if( !contact.firstContact )
    6.                 continue;
    7.  
    8.             if( !contact.isRigidbody )
    9.                 continue;
    10.  
    11.             if( contact.isKinematicRigidbody )
    12.                 continue;
    13.          
    14.             if( !contact.gameObject.CompareTag( tagsAndLayersProfile.contactRigidbodiesTag ) )
    15.                 continue;
    16.  
    17.             collisionResponseContacts.Add( contact );  
    18.         }

    Now there is no need to impose a certain behaviour within the CharacterActor itself, since basically you have the freedom of doing whatever you want with the contacts from outside (probably what most people are going to do). For example:

    Code (CSharp):
    1. for( int i = 0 ; i < CharacterActor.Contacts.Count ; i++ )
    2.         {
    3.             Contact contact = Contacts[i];
    4.            
    5.             // continue if the contact doesn't belong to the contact  layer mask
    6.             if( !CustomUtilities.BelongsToLayerMask( contact.gameObject.layer , contactLayerMask ) )
    7.                 continue;
    8.  
    9.             // Do something with this "contact"...
    10.  
    11.         }
     
    ikemen_blueD likes this.
  3. Luba

    Luba

    Joined:
    Oct 1, 2014
    Posts:
    49
    work in firts person?
     
  4. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    126
    Hi, yes it does, play the demo to see the result, press V to toggle between third person and first person. The character itself has almost nothing to do with the first person perspective, this is a camera thing (95% camera, 5% NormalMovement state).
     
  5. Luba

    Luba

    Joined:
    Oct 1, 2014
    Posts:
    49
    It has a swimming system, I just saw that you have animations in the project.
     
  6. dmarqs

    dmarqs

    Joined:
    Oct 16, 2013
    Posts:
    12
    Hi, me again.

    I bought the asset today and it has been really frustrating making it work. =/ I have experience, but I can't make it work.

    I'm trying following your doc (its unfortunately confusing):

    1- I created the blank character. The next step you asks to create a behaviour for controlling the character. But that doesn't really goes against what the asset offers? An 3d movement? I looked at your NormalMovement ( I couldn't find a mention of it during the 'How to...') and I copied the content. Is that the right approach? How can I have 3d movement without me writing too much of the code?

    2- After add the blank character (with NormalMovement) to my own scene, Scene Controller keeps giving me this exception

    NullReferenceException
    UnityEngine.Transform.get_rotation ()

    Don't know why it happens, in your own demo that doesn't happen. I really don't have anything in this scene, I just created it and followed along with your tutorial. I tried coping the Demo Player too but it keeps giving me that same exception.

    So as you figured already, I can't make the minimum work. =/

    Sorry if my words look harsh, but it has been very disappointing this whole afternoon trying to make it work. =/
     
  7. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    126
    Hi, check the movement reference, from the CharacterStateController, you are probably using a "external" movement reference with a null reference. Since the demo character was prepared for a tutorial in 1.0.5, which included the camera as well.


    If that's the case (probably is) i should've included a warning message, apologies for that :(, will include that in 1.1.1. Thanks for letting me know.

    ──────────────────────────────────────────────
    Also a quick fix for a stupid mistake i made (i found that yesterday). Replace the "for" in line 321 from CharacterStateController.cs

    Code (CSharp):
    1. for( int i = 0 ; i < transitionsQueue.Count ; i++ )
    with the following:

    Code (CSharp):
    1. while( transitionsQueue.Count != 0 )
    If you don't want to do this don't worry, version 1.1.1 (minor version) will be uploaded tomorrow, including this + the warning for the external movement reference.

    Not really, the asset allows you to move in a 2D/3D world, based on a set of rules defined by the character controller features (CharacterActor). If you use the same movement logic from the NormalMovement in a vainilla rigidbody, this will not be able to walk over steps, slopes, it will fall on edges, will not be able to stick to the ground, etc.

    The movement logic is really easy to do, probably represents the 2% of the asset. In fact the whole movement logic can be described as a fancy MoveTowards (Vector3) (although it has a bunch of clever tricks behind). This logic without the CharacterActor is kinda useless.

    From the start i didn't want to force you to move your character in a certain way, for example: you could add a velocity (to the existing one), or set the value frame by frame, maybe add a force, use a PID to set a target velocity (using acceleration/force), or maybe use a root motion-based character (more like all those locomotion system out there), ... there are a lot of ways to move a character.

    The NormalMovement state is a scrpt-based movement state that covers the basic movement of the character (it's more than enough for most cases). You can clone that, derive from that, or create your own state. In other words, it is basically an example, same for the rest of the states (that's why they are part of the Demo). Examples can be valuable as well, but the idea of this controller is to allow you to write your own logic (don't be "scared" with this, you can write your logic in 10 minutes), the CharacterActor should do the rest (plus the state controller). If you don't like that you can use the NormalMovement, it's perfectly fine.

    Yes :), i have a Swimming, RopeClimbing and AntiGravity (like the one in Prey) states for 1.2.0, but those will have to wait for now. They will be part of the demo.
     
    Last edited: Jul 2, 2020 at 12:17 AM
  8. dmarqs

    dmarqs

    Joined:
    Oct 16, 2013
    Posts:
    12
    Hi again,

    Thank you for your explanation and sorry again for the harsh words.

    I still have a few questions:

    Ok, NormalMovement is part of the Demo.

    Looking at your doc again you ask to create a class derived from CharacterActorBehaviour, which goes all the logics. But NormalMovement is a CharacterState and CharacterStateController is derived from CharacterActorBehaviour. So what should I do to create my own movement logic?

    1 - Add CharacterStateController and create my own 'NormalMovement'.
    2- Create a custom CharacterActorBehaviour. ( in this case, that custom class will be like my own 'NormalMovement'? )

    I liked how your demo character is organised, but would like to know how exactly you planned the use of CharacterState and CharacterActorBehaviour classes.


    Another question: I created another blank character now, added the tags and layers and fixed the line of code you asked. When I start the scene, the character don't start falling (it's in the air about the ground) Shouldn't start falling already?

    ˆˆˆˆˆˆˆˆˆ I edited the question above because I already figure it out. =) I was messing with your NormalMovement and found that you handle gravity here too.

    Thank you! =)
     
    Last edited: Jul 2, 2020 at 7:55 PM
  9. dmarqs

    dmarqs

    Joined:
    Oct 16, 2013
    Posts:
    12
    Hi again,

    I'm messing with your NormalMovement again. Why did you choose to separate stuff like ledge climbing but keep together jump and crouch under the same class? Is there any design decision behind that? Or it was just personal preference?
     
  10. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    126
    Hi, don't worry, unfortunately sometimes one user has to lose a day or two dealing with some stupid error, this is usually the only way i can note that something is missing, especially since i do most of the work based on demo scenes and prefabs. By the way i already submit version 1.1.1 (pending review).

    If something like this happens again, please send me an email, it will be much faster for me to fix it.

    That's a "Core" tutorial (if you will). This assumes you don't have any content from the implementation at your disposal (for example, you decided to implement your own "logic controller" on top, so you need to create a CharacterActorBehaviour for the CharacterActor). If you want to use the state machine (probably) then ignore this (because the state machine is a CharacterActorBehaviour).


    Indeed, to me gravity is just an acceleration, i never put gravity in a "special" place (like the Rigidbody component does). In the NormalMovement state, gravity means one more "velocity" (although it is an acceleration) applied to the character, you can ignore it or not.

    Because jumping involves just an impulse or change to vertical velocity, most games (especially platformers) use a jump in this way. However, LedgeClambing involves a change in the type of movement (now the character moves using a root motion-based logic), it also involves more specific parameters, inspector fields, another animator controller, etc. Putting all that in one state would be a mess.

    That said, there is not rule or criteria to define where a state starts and where it ends. To me, implementing the jump was easy to do within the NormalMovement state.
     
unityunity