ManualRVOAgent.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using UnityEngine;
  2. using System.Collections;
  3. namespace Pathfinding.Examples {
  4. using Pathfinding.RVO;
  5. /// <summary>
  6. /// Player controlled character which RVO agents will avoid.
  7. /// This script is intended to show how you can make NPCs avoid
  8. /// a player controlled (or otherwise externally controlled) character.
  9. ///
  10. /// See: Pathfinding.RVO.RVOController
  11. /// </summary>
  12. [RequireComponent(typeof(RVOController))]
  13. [HelpURL("http://arongranberg.com/astar/documentation/stable/class_pathfinding_1_1_examples_1_1_manual_r_v_o_agent.php")]
  14. public class ManualRVOAgent : MonoBehaviour {
  15. RVOController rvo;
  16. public float speed = 1;
  17. void Awake () {
  18. rvo = GetComponent<RVOController>();
  19. }
  20. void Update () {
  21. var x = Input.GetAxis("Horizontal");
  22. var y = Input.GetAxis("Vertical");
  23. var v = new Vector3(x, 0, y) * speed;
  24. // Override the RVOController's velocity. This will disable local avoidance calculations for one simulation step.
  25. rvo.velocity = v;
  26. transform.position += v * Time.deltaTime;
  27. }
  28. }
  29. }