We need to know f the force is active so we only invoke that OnForceCompleted once. Without it, the force never depletes and of course OnForceCompleted never invokes.
I have no idea how I missed that, but itās fixed (for now, still testing it). Thank you again Brian for saving me
By the way, considering the current state of the project, suppose I want to open it from another project name, computer or something else, what do I need to check for to get it to work? I just gave that a go (because I wanted to test something else), but that did not go as expected⦠I canāt even get my controllers to work when the game runs for some reason (not on my main project, but on a copy I tried making out of it)
I imported all the necessary libraries for that (otherwise it wonāt run)
You could zip up the project folder (but remove the Library, obj and Temp folders from the zip) and unzip it in a new directory. (It should be that simple). Then you just add the project from disk in the Unity Hub.
Using source control, itās even easier, you just clone the project using your git client, then add the project from disk in the Unity Hub.
SOO⦠Go to the unity project location, delete the temporary, library and object files and then unzip it wherever I want to take it⦠Got it!
Quick question by the way, for the randomization part of the script, when assigning āforceAmountā, did you mean āforce.sqrMagnitudeā on the Right Hand Side? Placing āforceAmountā gives errors (for obvious reasonsā¦)
Apart from that, the randomization isnāt working against the player, only the enemy⦠Iām guessing it has to do with the mathematical formula, Iām still trying to understand it
void Start()
{
MainCameraTransform = Camera.main.transform;
// The following check ensures that if we kill an enemy, save the game, quit and then return later, he is indeed dead
// (the reason it's here is because 'RestoreState()' happens between 'Awake()' and 'Start()', so to counter for the delay, we do it in start too)
if (Health.IsDead()) SwitchState(new PlayerDeathState(this));
else SwitchState(new PlayerFreeLookState(this));
Health.onDie.AddListener(() => {
SwitchState(new PlayerDeathState(this));
});
Health.onResurrection.AddListener(() => {
SwitchState(new PlayerFreeLookState(this));
});
ForceReceiver.OnForceApplied += HandleForceApplied;
}
See⦠youāre asking why it didnāt randomize, and the two things I wanted to see were if the method was subscribed to and what your randomize code looked like.
The code I provided was merely an example anyways.
lol ironically enough, even without the randomizer my player was not going into impact state for some reasonā¦
Anyway, here is my tuned attempt with the randomizer, for both the player and the enemy state machine:
PlayerStateMachine:
private void HandleForceApplied(Vector3 force)
{
if (Health.IsDead()) return;
float forceAmount = Random.Range(0f, force.sqrMagnitude);
if (forceAmount > Random.Range(0f, SkillStore.GetSkillLevel(Skill.Attack))) // I created a getter for the SkillStore...
{
SwitchState(new PlayerImpactState(this));
}
}
Whatās concerning me though, is that the impact state never gets entered for the player even without a randomizer, albeit the code is asking it to do soā¦
Edit: Through code debugging, the player enters the Impact state, but the animation is not playing for the player for some reason⦠I checked the hash, all seems wellā¦
Edit 2: Entering and Exiting the Impact state work perfectly fine⦠now Iām going nuts about why in the world is the animation not playing!
Edit 3: LOOOOOOOOOOOOOOOOL I had ZERO Hit force applied to my first attack with the 1H-Sword, NO WONDER IT WASNāT WORKING!
the NavMeshAgent bug is back, but with a brand new error set (I checked the bake settings, all is good on that part):
"SetDestination" can only be called on an active agent that has been placed on a NavMesh.
UnityEngine.AI.NavMeshAgent:set_destination (UnityEngine.Vector3)
RPG.States.Enemies.EnemyChasingState:MoveToPlayer (single) (at Assets/Project Backup/Scripts/State Machines/Enemy/EnemyChasingState.cs:64)
RPG.States.Enemies.EnemyChasingState:Tick (single) (at Assets/Project Backup/Scripts/State Machines/Enemy/EnemyChasingState.cs:33)
RPG.States.StateMachine:Update () (at Assets/Project Backup/Scripts/State Machines/StateMachine.cs:18)
"ResetPath" can only be called on an active agent that has been placed on a NavMesh.
UnityEngine.StackTraceUtility:ExtractStackTrace ()
RPG.States.Enemies.EnemyChasingState:Exit () (at Assets/Project Backup/Scripts/State Machines/Enemy/EnemyChasingState.cs:53)
RPG.States.StateMachine:SwitchState (RPG.States.State) (at Assets/Project Backup/Scripts/State Machines/StateMachine.cs:11)
RPG.States.Enemies.EnemyChasingState:Tick (single) (at Assets/Project Backup/Scripts/State Machines/Enemy/EnemyChasingState.cs:28)
RPG.States.StateMachine:Update () (at Assets/Project Backup/Scripts/State Machines/StateMachine.cs:18)
This time, itās all coming from the āEnemyChasingState.csā - Iāll try figure this one out before you see it
Iām genuinely confused as to how the enemy could be following the patrol path or chasing the player if itās not on the NavMeshā¦
Once again, are these red errors stacking up really fast or yellow warnings that donāt repeat until the next time?
red errors that stack up really fast (and he wonāt move beyond a specific difference⦠so if heās x meters away from the player, heāll get stuck on his navmesh if he canāt find a way back. Iām being extra careful with my Patrol points as well so that he doesnāt go nuts)
and heās on a blue, nicely baked NavMesh by the way
that was an easy and quick fix, and everything works well now⦠(the red errors still pop up, but now he can actually chase me around the terrain with no issues, so all is good for the moment). Thank you again
That aside, there are only two scripts, the āCooldownTokenManager.csā and the āEventPool.csā, right? Do those go on the player and enemies, or⦠where do they go?
Itās not that itās left empty, itās that both ideas were conquered with the one section. Eventually, Iām going to flesh out the whole thing and break down step by step how I got to the final script, but I ran out of time to work on writing this, so, realizing that where we are right now is sufficient for enemy throttling (the rest is almost all about eliminating Update and allowing UI to easily react to the timers). Iāll eventually go back and finish the rest. For now, the finished classes are in place.
The CooldownTokenManager will go on both the Player and the Enemies and and will need to be added to the [field:SerializeField] like the rest of the components (weāll cover that in the next section). The EventPool is not a MonoBehaviour, itās a class thatās used (three times!) in the CooldownTokenManager.