12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- using UnityEngine;
- using Pathfinding;
- using System.Collections.Generic;
- namespace Pathfinding.Legacy {
- using Pathfinding.RVO;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- [AddComponentMenu("Pathfinding/Legacy/Local Avoidance/Legacy RVO Controller")]
- [HelpURL("http://arongranberg.com/astar/documentation/stable/class_pathfinding_1_1_legacy_1_1_legacy_r_v_o_controller.php")]
- public class LegacyRVOController : RVOController {
-
-
-
-
- [Tooltip("Layer mask for the ground. The RVOController will raycast down to check for the ground to figure out where to place the agent")]
- public new LayerMask mask = -1;
- public new bool enableRotation = true;
- public new float rotationSpeed = 30;
- public void Update () {
- if (rvoAgent == null) return;
- RaycastHit hit;
- Vector3 pos = tr.position + CalculateMovementDelta(Time.deltaTime);
- if (mask != 0 && Physics.Raycast(pos + Vector3.up*height*0.5f, Vector3.down, out hit, float.PositiveInfinity, mask)) {
- pos.y = hit.point.y;
- } else {
- pos.y = 0;
- }
- tr.position = pos + Vector3.up*(height*0.5f - center);
- if (enableRotation && velocity != Vector3.zero) transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(velocity), Time.deltaTime * rotationSpeed * Mathf.Min(velocity.magnitude, 0.2f));
- }
- }
- }
|