Пример #1
0
 void Update()
 {
     if (HolisticMath.Distance(new Coords(this.transform.position),
                               new Coords(fuel.transform.position)) > stopping)
     {
         this.transform.position += direction * speed * Time.deltaTime;
     }
 }
Пример #2
0
    static public Coords GetNormal(Coords vector)
    {
        float length = HolisticMath.Distance(new Coords(0, 0, 0), vector);

        vector.x /= length;
        vector.y /= length;
        vector.z /= length;

        return(vector);
    }
Пример #3
0
    void Update()
    {
        // If direction is declared here, the tank deacelerates when is near the fuel
        // This happens because transform.position increases each frame, in this way
        // direction decreaces each frame.
        // The tank will almost reach the fuel, but never will exactly reach it
        // so, its necessary a stopping condition to stop the tank
        //direction = fuel.transform.position - transform.position;

        if (HolisticMath.Distance(new Coords(transform.position), new Coords(fuel.transform.position)) > stoppingDistance)
        {
            // multiply by Time.deltaTime ensures a more consistent movement, independent of fps
            transform.position += direction * speed * Time.deltaTime;
        }
    }
    static public Coords Translate(Coords position, Coords facing, Coords vector)
    {
        if (HolisticMath.Distance(new Coords(0, 0, 0), vector) <= 0)
        {
            return(position);
        }
        float angle      = HolisticMath.Angle(vector, facing);
        float worldAngle = HolisticMath.Angle(vector, new Coords(0, 1, 0));
        bool  clockwise  = false;

        if (HolisticMath.Cross(vector, facing).z < 0)
        {
            clockwise = true;
        }

        vector = HolisticMath.Rotate(vector, angle + worldAngle, clockwise);

        float xVal = position.x + vector.x;
        float yVal = position.y + vector.y;
        float zVal = position.z + vector.z;

        return(new Coords(xVal, yVal, zVal));
    }
Пример #5
0
    public Coords GetNormal()
    {
        float magnitude = HolisticMath.Distance(new Coords(0, 0, 0), new Coords(x, y, z));

        return(new Coords(x / magnitude, y / magnitude, z / magnitude));
    }