Make NavMeshAgent Run

Tom

New member
I have set up a TopDownCamera together with the Third Person Controller. The scene contains a baked NavMesh and a small script, that make a raycast on click and sends the player to the destination (by using NavMeshAgent.SetDestination. I extended my script to detect double clicks which should send my character running towards the destination. But I can't figure out how to specify to run in this case.
 
Ah, I totally skipped the SpeedChange Ability when browsing through the list. Tested it, and works, but I will have to dive into the documentation to see, how to access abilities the correct way. This works, but does not feel right at all:

C#:
if(Input.GetKeyDown(KeyCode.LeftShift))
    _characterLocomotion.Abilities.OfType<SpeedChange>().First().StartAbility();
if(Input.GetKeyUp(KeyCode.LeftShift))
    _characterLocomotion.Abilities.OfType<SpeedChange>().First().StopAbility();
 
Top