Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Vector3 pointOnBezier(float aProgress,bool aMovingLeft,bool aMovingRight) {
- if (nextPoint == null&&loopPoint==null) {
- return this.transform.position;
- }
- Vector3 ret = new Vector3 ();
- if (loopPoint != null) {
- return handleLoopPoint (aProgress);
- } else
- if (!aMovingLeft && !aMovingRight) {
- return notMovingLeftOrRight (aProgress);
- }
- if (aMovingLeft) {
- return handleMovingLeft (aProgress);
- }
- if (aMovingRight) {
- return handleMovingRight (aProgress);
- }
- return ret;
- }
- private Vector3 handleLoopPoint(float aProgress) {
- Vector3 ret = new Vector3 ();
- if (controlPointStandard == null) {
- controlPointStandard = new GameObject ("CP");
- controlPointStandard.transform.SetParent (this.transform);
- this.controlPointStandard.transform.position = this.transform.position + ((this.loopPoint.transform.position - this.transform.position) / 2);
- }
- ret.x = (1 - aProgress) * (1 - aProgress) * this.transform.position.x + 2 * (1 - aProgress) * aProgress * this.controlPoint.x + aProgress * aProgress * this.loopPoint.transform.position.x;
- ret.z = (1 - aProgress) * (1 - aProgress) * this.transform.position.z + 2 * (1 - aProgress) * aProgress * this.controlPoint.z + aProgress * aProgress * this.loopPoint.transform.position.z;
- ret.y = this.transform.position.y;
- return ret;
- }
- private Vector3 handleMovingRight(float aProgress) {
- Vector3 ret = new Vector3 ();
- if (futureRightPoint == null) {
- findFutureRightPoint ();
- }
- if (futureRightPoint != null) {
- Vector3 rightControlPoint = this.transform.position + ((futureRightPoint.transform.position - this.transform.position) / 2);
- ret.x = (1 - aProgress) * (1 - aProgress) * this.transform.position.x + 2 * (1 - aProgress) * aProgress * rightControlPoint.x + aProgress * aProgress * futureRightPoint.transform.position.x;
- ret.z = (1 - aProgress) * (1 - aProgress) * this.transform.position.z + 2 * (1 - aProgress) * aProgress * rightControlPoint.z + aProgress * aProgress * futureRightPoint.transform.position.z;
- ret.y = this.transform.position.y;
- }
- return ret;
- }
- private Vector3 handleMovingLeft(float aProgress) {
- Vector3 ret = new Vector3 ();
- if (futureLeftPoint == null) {
- findFutureLeftPoint ();
- }
- if (futureLeftPoint != null) {
- Vector3 leftControlPoint = this.transform.position + ((futureLeftPoint.transform.position - this.transform.position) / 2);
- ret.x = (1 - aProgress) * (1 - aProgress) * this.transform.position.x + 2 * (1 - aProgress) * aProgress * leftControlPoint.x + aProgress * aProgress * futureLeftPoint.transform.position.x;
- ret.z = (1 - aProgress) * (1 - aProgress) * this.transform.position.z + 2 * (1 - aProgress) * aProgress * leftControlPoint.z + aProgress * aProgress * futureLeftPoint.transform.position.z;
- ret.y = this.transform.position.y;
- }
- return ret;
- }
- private Vector3 notMovingLeftOrRight(float aProgress) {
- Vector3 ret = new Vector3 ();
- if (controlPointStandard == null) {
- controlPointStandard = new GameObject ("CP");
- controlPointStandard.transform.SetParent (this.transform);
- this.controlPointStandard.transform.position = this.transform.position + ((this.nextPoint.transform.position - this.transform.position) / 2);
- }
- ret.x = (1 - aProgress) * (1 - aProgress) * this.transform.position.x + 2 * (1 - aProgress) * aProgress * this.controlPoint.x + aProgress * aProgress * this.nextPoint.transform.position.x;
- ret.z = (1 - aProgress) * (1 - aProgress) * this.transform.position.z + 2 * (1 - aProgress) * aProgress * this.controlPoint.z + aProgress * aProgress * this.nextPoint.transform.position.z;
- ret.y = this.transform.position.y;
- return ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement