Advertisement
Guest User

Untitled

a guest
Jan 3rd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using Pathfinding.RVO;
  5.  
  6. namespace Pathfinding.RVO
  7. {
  8. [HelpURL("http://arongranberg.com/astar/docs/class_pathfinding_1_1_examples_1_1_r_v_o_example_agent.php")]
  9. public class RVORotationUnitPathMovement : RVOUnitSimplePathMovement, IRVOMovement
  10. {
  11.  
  12. #region variables
  13. // Vlad's extra edit
  14. private float _initialMaxSpeed;
  15. private bool _isSlownDown = false;
  16. private float _minRotationAngle = 46;
  17. #endregion variables
  18.  
  19.  
  20.  
  21. #region init
  22. public override void Start()
  23. {
  24. _initialMaxSpeed = maxSpeed;
  25. }
  26. #endregion init
  27.  
  28. #region override
  29. public override void AdjustSpeedOnRotation(Vector3 movementDelta)
  30. {
  31. float crtAng = RotateInThisDirection(movementDelta);
  32. float targetAng = Mathf.Atan2(movementDelta.y, movementDelta.x) * Mathf.Rad2Deg;
  33. if (targetAng < 0) { targetAng += 360; }
  34. float outComeAngle = Mathf.Abs(targetAng - crtAng);
  35.  
  36. if (outComeAngle < _minRotationAngle || (360 - outComeAngle) < _minRotationAngle)
  37. {
  38. if (_isSlownDown)
  39. {
  40. _isSlownDown = false;
  41. maxSpeed = _initialMaxSpeed;
  42. }
  43. } else {
  44. if (!_isSlownDown)
  45. {
  46. _isSlownDown = true;
  47. maxSpeed = 0.01f;
  48. }
  49. }
  50. }
  51. #endregion override
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement