예제 #1
0
 // Update is called once per frame
 void Update()
 {
     distance = VecLib.VecMag(VecLib.VectorSub(transform.position, paths[target].transform.position)); // finds the distance between the square and the waypoint.
     if (distance < Tolerence)                                                                         // if the distance is less that the tolerance then the target changes
     {
         target++;
         if (target >= paths.Length) // if there is no other targets the cube goes back to the first target.
         {
             target = 0;
         }
     }
     VecTemp            = VecLib.UnitDirVec(paths[target].transform.position, transform.position); // holds the unit vector between the waypoint and the square
     Vel                = VecLib.ScalarMult(VecTemp, speed * Time.deltaTime);                      // makes the velocity the unit vector * speed
     transform.position = VecLib.VectorAdd(transform.position, Vel);                               // adds velocity to the position of the cube (allows to move).
 }
예제 #2
0
    void Collisionball()
    {
        Targetdistance = VecLib.VectorSub(ball2.transform.position, transform.position);
        if (VecLib.VecDotP(Targetdistance, Velocity) >= 0)
        {
            //equation 1 for conservation of momentum
            m          = 2 * ball2.mass / mass + ball2.mass;
            equationp1 = VecLib.VecDotP(VecLib.VectorSub(Velocity, ball2.Velocity), VecLib.VectorSub(transform.position, ball2.transform.position)) / Mathf.Pow(VecLib.VecMag(VecLib.VectorSub(transform.position, ball2.transform.position)), 2);
            Vecsub1    = VecLib.VectorSub(transform.position, ball2.transform.position);
            Velocity   = VecLib.VectorSub(Velocity, VecLib.ScalarMult(Vecsub1, m * equationp1));
        }

        Targetdistance = VecLib.VectorSub(transform.position, ball2.transform.position);
        if (VecLib.VecDotP(Targetdistance, ball2.Velocity) >= 0)
        {
            //equation 2 for conservation of momentum
            m              = 2 * mass / mass + ball2.mass;
            equationp1     = VecLib.VecDotP(VecLib.VectorSub(ball2.Velocity, Velocity), VecLib.VectorSub(ball2.transform.position, transform.position)) / Mathf.Pow(VecLib.VecMag(VecLib.VectorSub(ball2.transform.position, transform.position)), 2);
            Vecsub1        = VecLib.VectorSub(ball2.transform.position, transform.position);
            ball2.Velocity = VecLib.VectorSub(ball2.Velocity, VecLib.ScalarMult(Vecsub1, m * equationp1));
        }
    }