Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 KB | None | 0 0
  1. public Vector3 pointOnBezier(float aProgress,bool aMovingLeft,bool aMovingRight) {
  2. if (nextPoint == null&&loopPoint==null) {
  3. return this.transform.position;
  4. }
  5.  
  6. Vector3 ret = new Vector3 ();
  7. if (loopPoint != null) {
  8. return handleLoopPoint (aProgress);
  9. } else
  10. if (!aMovingLeft && !aMovingRight) {
  11. return notMovingLeftOrRight (aProgress);
  12. }
  13. if (aMovingLeft) {
  14. return handleMovingLeft (aProgress);
  15. }
  16. if (aMovingRight) {
  17. return handleMovingRight (aProgress);
  18. }
  19. return ret;
  20. }
  21. private Vector3 handleLoopPoint(float aProgress) {
  22. Vector3 ret = new Vector3 ();
  23. if (controlPointStandard == null) {
  24. controlPointStandard = new GameObject ("CP");
  25. controlPointStandard.transform.SetParent (this.transform);
  26. this.controlPointStandard.transform.position = this.transform.position + ((this.loopPoint.transform.position - this.transform.position) / 2);
  27.  
  28. }
  29.  
  30. ret.x = (1 - aProgress) * (1 - aProgress) * this.transform.position.x + 2 * (1 - aProgress) * aProgress * this.controlPoint.x + aProgress * aProgress * this.loopPoint.transform.position.x;
  31. ret.z = (1 - aProgress) * (1 - aProgress) * this.transform.position.z + 2 * (1 - aProgress) * aProgress * this.controlPoint.z + aProgress * aProgress * this.loopPoint.transform.position.z;
  32. ret.y = this.transform.position.y;
  33. return ret;
  34. }
  35. private Vector3 handleMovingRight(float aProgress) {
  36. Vector3 ret = new Vector3 ();
  37. if (futureRightPoint == null) {
  38. findFutureRightPoint ();
  39. }
  40. if (futureRightPoint != null) {
  41. Vector3 rightControlPoint = this.transform.position + ((futureRightPoint.transform.position - this.transform.position) / 2);
  42. ret.x = (1 - aProgress) * (1 - aProgress) * this.transform.position.x + 2 * (1 - aProgress) * aProgress * rightControlPoint.x + aProgress * aProgress * futureRightPoint.transform.position.x;
  43. ret.z = (1 - aProgress) * (1 - aProgress) * this.transform.position.z + 2 * (1 - aProgress) * aProgress * rightControlPoint.z + aProgress * aProgress * futureRightPoint.transform.position.z;
  44. ret.y = this.transform.position.y;
  45. }
  46. return ret;
  47. }
  48. private Vector3 handleMovingLeft(float aProgress) {
  49. Vector3 ret = new Vector3 ();
  50. if (futureLeftPoint == null) {
  51. findFutureLeftPoint ();
  52. }
  53. if (futureLeftPoint != null) {
  54. Vector3 leftControlPoint = this.transform.position + ((futureLeftPoint.transform.position - this.transform.position) / 2);
  55.  
  56. ret.x = (1 - aProgress) * (1 - aProgress) * this.transform.position.x + 2 * (1 - aProgress) * aProgress * leftControlPoint.x + aProgress * aProgress * futureLeftPoint.transform.position.x;
  57. ret.z = (1 - aProgress) * (1 - aProgress) * this.transform.position.z + 2 * (1 - aProgress) * aProgress * leftControlPoint.z + aProgress * aProgress * futureLeftPoint.transform.position.z;
  58. ret.y = this.transform.position.y;
  59. }
  60. return ret;
  61. }
  62. private Vector3 notMovingLeftOrRight(float aProgress) {
  63. Vector3 ret = new Vector3 ();
  64. if (controlPointStandard == null) {
  65. controlPointStandard = new GameObject ("CP");
  66. controlPointStandard.transform.SetParent (this.transform);
  67. this.controlPointStandard.transform.position = this.transform.position + ((this.nextPoint.transform.position - this.transform.position) / 2);
  68.  
  69. }
  70. ret.x = (1 - aProgress) * (1 - aProgress) * this.transform.position.x + 2 * (1 - aProgress) * aProgress * this.controlPoint.x + aProgress * aProgress * this.nextPoint.transform.position.x;
  71. ret.z = (1 - aProgress) * (1 - aProgress) * this.transform.position.z + 2 * (1 - aProgress) * aProgress * this.controlPoint.z + aProgress * aProgress * this.nextPoint.transform.position.z;
  72. ret.y = this.transform.position.y;
  73. return ret;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement