Merging the Third Person Controller Course with the RPG Course

One.

When we get to enemies, then weā€™ll create another more streamlined version (and non humanoid enemies will each need their own as well, like say, a spider). Weā€™ll burn that bridge when we get to it.

Yup, done with the new Animator, and it works well (obviously had to swap it in the Play hierarchy as well, just documenting it here so I donā€™t forget later)

Iā€™ll continue the rest of the lectures either tonight or tomorrow, but so far so good :slight_smile:

Quick question on the fly, before I start throwing more doubts hereā€¦ how do you stop the camera from going nuts when you exit targeting state? When we go from targeting to freelook, it rotates like crazy for a second before being stable again. I tried fixing that in the main course as well, but failed. Thatā€¦ and the side dodging system both failed

and before we get into attacking states, itā€™s completely normal that my player tends to run from fights (i.e: step back) if heā€™s in a fight in targeting state?

Nathan addresses this in one of the later lectures in the course, I donā€™t have the solution off hand here at work at the moment (nor the time to re-watch those sections to find it)

Once you switch to the targeting state, youā€™ll constantly face the enemy and your controllerā€™s movement will be relative to the player, not the camera.

I thought it was regarding the collider being set to just ignore the player collider, but apparently notā€¦ Iā€™ll try search it up :slight_smile:

True, but if I get close to the enemy, like too close, my player tends to want to try step back a few steps for some reason (not sure why, but I think the attacking issue should be gone by the time the new system is in). It only happens when the real-life player tries clicking the attack button with his mouse

Which also results in this error:

"Stop" can only be called on an active agent that has been placed on a NavMesh.
UnityEngine.StackTraceUtility:ExtractStackTrace ()
RPG.Movement.Mover:Cancel () (at Assets/Scripts/Movement/Mover.cs:66)
RPG.Combat.Fighter:Update () (at Assets/Scripts/Combat/Fighter.cs:65)

Just another question from the ā€˜Attackingā€™ lecturesā€¦ youā€™re using the solution you once taught me for my 2H Sword to apply a hit value, right? Where we find a specific time in an animation to trigger a hit function if Iā€™m not mistaken

Yes, but since there is no ā€œtargetā€ (well, there is if youā€™re in targeting mode, but not in FreeLook), rather than just hitting a set target, weā€™ll do a OverlapSphere test to get all characters within a certain range and damage them.

On the Cinemachine collider, you do set it to ignore the player. Canā€™t tell you how from work, but I thought I put it in the tutorial.

I left that alone for most of the tutorial, but what you want to do is

  • Remove the PlayerController
  • Add an if(CompareTag(ā€œPlayerā€)) return; in Fighterā€™s Update and Attack() methods.

Fair enough, Iā€™ll give it a go in the morning. I threw in a RAW ā€˜PlayerAttackingState.csā€™ into the test project and it went wild with the errorsā€¦ Figured Iā€™d give it a break tonight :grinning_face_with_smiling_eyes:

Will check the rest as well soon :slight_smile:

Regarding the Cinemachine collider ignoring the player, I manually did that a while ago, but the camera still goes wild. I even tried changing the layers to make it stop flying over collide objects, still failed

Try downloading the course project against the repo lecture (ideally, what you would do is clone the repo and move the commit to the lecture, then it looks exactly like it does at that page, but you can also just download the zip directly). Then compare the settings on the camera(s) in the course project to the settings on the camera(s) in yours. Hint: I actually tried to stay pretty close to what Nathan did.

The Attacking State and the Attack are things that (by necessity) will start seeing significant changes from the Third Person Course, and my lectures get a bit more verbose starting there.

By course project, youā€™re talking about the third person course? Iā€™m cross checking my copy of the third person against the test copy Iā€™m trying to implement this system on, to see why my camera acts wild (ill recheck it tomorrow)

Or is there a copy of the third person I can also downloadā€¦?!

Edit: you said repoā€¦ Iā€™ll check that in the morning :slight_smile:

At the bottom of each page in this tutorial is
This Pageā€™s GitLab Commit
If you click on this link, you can see the project exactly as it was when I wrote the page (just like our lectures in our courses)
From there, click on Browse Files, then Code, an you can download the Zip of the course

umm, Brianā€¦ at the end of lecture 19, itā€™s normal that ā€˜PlayerAttackingState.csā€™ has no access to ā€˜Fighter.csā€™ (at least ā€˜stateMachine.Fighterā€™), or a function known as ā€˜SetLocomotionState()ā€™ā€¦? Because itā€™s complaining about these two right now

Neither of these things would be normal, noā€¦

In PlayerStateMachine, the declaration for Fighter should be

[field: SerializeField] public Fighter Fighter {get; private set;}

Meaning you should have read access, but you shouldnā€™t be able to change the value of Fighter (you can call all public functions and read public properties on Fighter, but you canā€™t say stateMachine.Fighter = something).

SetLocomotionState should be in PlayerBaseState.cs (Iā€™ll edit that in the lesson, I think I neglected to mention it. If you recall from the Third Person Course (and at this point, I tried to stay as close as possible until this lesson to the TPC), SetLocomotionState (or it might have been ReturnToLocomotionState simply checks to see if we have a target in targeter and decides whether to return to PlayerFreeLookState or PlayerTargetingState

        protected void SetLocomotionState()
        {
            stateMachine.SwitchState(stateMachine.Targeter.CurrentTarget?new PlayerTargetingState(stateMachine) : new PlayerFreeLookState(stateMachine));
        }

fair enough, thanks Brian

There were some other variables as well that changed and were not properly mentioned, like the animation float trigger namesā€¦ This one took me a while to figure out what I was doing to solve it :stuck_out_tongue_winking_eye: (all is good now though). We all slip though, so itā€™s okay :slight_smile:

Iā€™m about to start lecture 21, and so far Iā€™m surprised we never added the attack arrays into the state machine. From a quick look, it doesnā€™t seem like the ā€˜PlayerStateMachine.csā€™ script will be tackled in this lecture eitherā€¦ :sweat_smile: - How do we get the player to actually play the attack animations and deal the damage though? Iā€™m genuinely confused (so far if I click somewhere, he doesnā€™t attackā€¦ he just freezes in whatever motion state heā€™s in, until I lift my mouse button up)

This was quite literally being set up in lecture 19ā€¦ We donā€™t add the attacks in PlayerStateMachine because this would make swappable weapons extremely difficult.
Attacks are ScriptableObjects, which must be created with right clicks like WeaponConfigs
The WeaponConfig contains an array of attacks, but for now, itā€™s only considering the 1st entry in the attack

PlayerAttackingState gets itā€™s Attack data from Fighter, if an integer is passed into PlayerAttackState (when we enter AttackState from a locomotion state) or Fighter is given the Attack data from an actual Attack reference (from the Attack combo field) if this is a combo attack.

When we enter PlayerAttackState, the last line in Enter() is a CrossFadeInFixedTime to the currentAttackā€™s attack state in the animator.

OK Iā€™ll give this a go and see how it turns outā€¦ I was extremely confused as of whatā€™s going on there, but I think Iā€™m catching the idea now. Attacks donā€™t need to be in some resource folder though, unlike WeaponConfigs, right?

Thatā€™s correct. In mine, I kept the Attacks in the same folder as the Weapon object just for convenience.
Remember that for combo attacks, youā€™ll be putting in another Attack ScriptableObject. That Combo Attack does not need to be in the WeaponConfig at all.

For me, Iā€™m placing them in a unique ā€˜Attacksā€™ folder, that just contains folders that contain unique animations for each weapon (including the unarmed)

Quick question (and problem next) though: for the WeaponConfig attacks, we just add one attack, and that attack can have a trail of ā€˜Next Combo Attacksā€™, instead of adding them all, am I right?

And my problem right now isā€¦ the punches donā€™t land any sort of damage (and tbh I might turn off the loop time/strip some animation times out, because some of them are extremely slow)

Yes, for now. The long term goal is to have some randomnessā€¦ so you might have 3 or 4 starter attacks each with their own combo chainā€¦ (of course, you have to have the animations to back that up). The last attack in the chain simply has no combo attack assigned.

loop time??? No attack animations should have looping or you wonā€™t be able to detect their endā€¦

Did you add a TryHit Animation Event with a 1 or 2 for right/left hand?

Privacy & Terms