I thought it would look nice if the Enemy walked whilst patrolling. Currently I’m doing this with two new fields, “walkingSpeed” and “runningSpeed”, which I set directly in the Update() each frame via navMeshAgent.speed depending upon whether PatrolBehaviour() is called or not.
Will we encounter walking in a later tutorial or should I stick to my custom implementation?
I literally was just coming back to this post to say that same thing as I am on that video right now… will be interesting to see if my solution was similar…
It’s not displayed because the software thinks it’s a malformed html tag. Try selecting the code and pressing the button marked </>, or if you’re doing a block of code, you can press the backwards ’ key (next to the 1 on your keyboard, the one you shift to get a ~) three times and press enter. This will put you in “code” mode. Type the same backwards single quote three times again to exit code mode.
Not in Code Mode:
GetComponent().speed = patrollspeed;
In Code Mode:
I too felt the patrolling was a bit too energetic, so I made a simple implementation by adding some fields on the Mover component along with some methods.
FUNCTION : When player holds the left shift key, when clicking on terrain or enemy the player will accelerate to a defined speed. If the left shift key is released then the player’s speed returns to its initial value;
Stick those few lines (or a facsimile that you modify) at the beginning of PlayerController.cs / Void Update() just after checking if the player is dead but BEFORE calling the mover and fighter functions.
It is a VERY basic feature but it gives me the walk or run option plus can be expanded into its own method later for polishes down the road.