Пример #1
0
 private void SetRotationVariables()
 {
     directionConcesutiveWaypoints = MyVector3.Subtract(waypoints_position[NextTarget()], waypoints_position[target]).ToCylindrical();
     rotationPosition = MyVector3.Subtract(position, waypoints_position[target]).ToCylindrical();
     if (rotationPosition.getRadius() > 0)
     {
         angularVelocity = velocity / rotationPosition.getRadius();
         rotating        = true;
         float angle = MyVector3_Cylindrical.DeltaAngleRadiants(rotationPosition, directionConcesutiveWaypoints);
         //choose the rotation direction so that the bll always travels along the longest arc
         if (angle >= Mathf.PI)
         {
             clockwise = true;
         }
         else
         {
             clockwise = false;
         }
     }
     else
     {//the ball is exactly on top of the waypoint.
      //No rotation occurs in this case and the ball moves towards the next waypoint
         MakeRed(target);
         target = NextTarget();
         MakeGreen(target);
         MakeYellow(NextTarget());
         movementDirection = MyVector3.DirectionalUnitVector(position, waypoints_position[target]);
     }
 }
Пример #2
0
 public void Calculate()
 {
     try
     {//parse strings into floating point numbers
         float pos1_x = Single.Parse(pos1_inputs[0].text);
         float pos1_y = Single.Parse(pos1_inputs[1].text);
         float pos1_z = Single.Parse(pos1_inputs[2].text);
         float pos2_x = Single.Parse(pos2_inputs[0].text);
         float pos2_y = Single.Parse(pos2_inputs[1].text);
         float pos2_z = Single.Parse(pos2_inputs[2].text);
         float num    = Single.Parse(radius_input.text);
         if (num < 0)
         {
             throw new Exception("Only positive radii allowed!");
         }
         pos1   = new MyVector3(pos1_x, pos1_y, pos1_z);
         pos2   = new MyVector3(pos2_x, pos2_y, pos2_z);
         radius = num;
     }
     catch (Exception e)
     {//parsing failed
         Debug.LogError(e.Message);
         pos1_inputs[0].text = "";
         pos1_inputs[1].text = "";
         pos1_inputs[2].text = "";
         pos2_inputs[0].text = "";
         pos2_inputs[1].text = "";
         pos2_inputs[2].text = "";
         radius_input.text   = "";
         return;
     }
     //printe vectors to the scene
     directionalUnitVect.text = MyVector3.DirectionalUnitVector(pos1, pos2).Print();
     closerThanRadius.text    = MyVector3.CloserThanRadius(pos1, pos2, radius).ToString();
 }
Пример #3
0
 private void SetLinearMovementVariables()
 {
     rotationPosition = new MyVector3_Cylindrical(
         rotationPosition.getRadius(),
         directionConcesutiveWaypoints.getAzmuthalRad(), //place ball exctly between the current and the next waypoint
         rotationPosition.getY());
     rotating = false;
     position = MyVector3.Add(rotationPosition.ToCartesian(), waypoints_position[target]);
     MakeRed(target);
     target = NextTarget();
     MakeGreen(target);
     MakeYellow(NextTarget());
     movementDirection = MyVector3.DirectionalUnitVector(position, waypoints_position[target]);
 }
Пример #4
0
 // Start is called before the first frame update
 void Start()
 {
     position           = ToMyVector3(gameObject.transform.position);
     waypoints_position = new MyVector3[waypoints.Length];
     for (int i = 0; i < waypoints.Length; i++)
     {
         waypoints_position[i] = ToMyVector3(waypoints[i].position);
     }
     target = 0;
     MakeGreen(target);
     MakeYellow(NextTarget());
     rotationPosition  = MyVector3.Subtract(position, waypoints_position[target]).ToCylindrical();
     movementDirection = MyVector3.DirectionalUnitVector(position, waypoints_position[target]);
     rotating          = false;
 }