Ejemplo n.º 1
0
 public override void OnDrag(DragSummary dragSummary)
 {
     if (usesTopDownView)
     {
         lineDrawer.AddLine(new Vector3(dragSummary.position.x, this.transform.position.y, dragSummary.position.z));
     }
     else
     {
         lineDrawer.AddLine(new Vector3(dragSummary.position.x, dragSummary.position.y, this.transform.position.z));
     }
 }
    private void drawVelocityLine()
    {
        LineDrawer.RemoveLine(previousVelocityLineHash);
        float   percentTowardsMax = this.currentVelocity.magnitude / MAX_LIN_VELO;
        Vector2 endPt             = this.currentPosition + (this.currentVelocity.normalized * percentTowardsMax);

        previousVelocityLineHash = LineDrawer.AddLine(this.transform.position, endPt);
    }
    private void drawDirectionLine()
    {
        LineDrawer.RemoveLine(previousDirLineHash);
        Vector2 endPt = this.currentPosition;

        float radius = 0.3f;

        endPt.x            += Mathf.Cos(directionFacing) * radius;
        endPt.y            += Mathf.Sin(directionFacing) * radius;
        previousDirLineHash = LineDrawer.AddLine(this.currentPosition, endPt, Color.black);
    }
Ejemplo n.º 4
0
    public void AddLine(Line newLine)
    {
        /*
         * A new line is added to the game area. Add this new line to
         * this gameController's line tracker and the lineDrawer's lines.
         */

        RefreshLine(newLine);
        lines.Add(newLine);
        lineDrawer.AddLine(newLine);
    }
    private void drawAccelLine()
    {
        LineDrawer.RemoveLine(previousAccelerationLineHash);
        float percentTowardsMax = this.currentAcceleration.magnitude / MAX_LIN_ACC;

        // Bump the acceleration line so not to block the velocity line
        Vector2 bump    = new Vector2(0.01f, 0.01f);
        Vector2 endPt   = this.currentPosition + (this.currentAcceleration.normalized * percentTowardsMax) + bump;
        Vector2 startPt = this.currentPosition + bump;

        previousAccelerationLineHash = LineDrawer.AddLine(startPt, endPt, Color.red);
    }
Ejemplo n.º 6
0
    private void Update()
    {
        if (hasUpdate)
        {
            float oldx, oldy, oldz;
            //System.Diagnostics.Debug.WriteLine("hasUpdate TRUE");

            oldx = transform.position.x;
            oldy = transform.position.y;
            oldz = transform.position.z;

            // done moving. For some reason "==" is approximate :)
            if (oldx == targetX && oldy == targetY && oldz == targetZ)
            {
                //System.Diagnostics.Debug.WriteLine("STOPPED moving");
                hasUpdate = false;
                return;
            }

            // Move the GameObject but gradually
            Vector3 start      = transform.position;
            Vector3 end        = new Vector3(targetX, targetY, targetZ);
            Vector3 distanceTo = end - start;

            float smooth = 1.0f; // heuristically determined smoothing rate; tweak as needed
            transform.position = Vector3.MoveTowards(start, end, Time.deltaTime * smooth);
            //transform.position = end; // herky jerky motion - no smoothing

            // Draw trajectory
            if (drawTrajectories)
            {
                ld.AddLine(new Vector3(oldx, oldy, oldz), transform.position, Color.magenta);
            }
            //debug.drawline looks better but only works in Unity editor
            //Debug.DrawLine(new Vector3(oldx, oldy, oldz), transform.position, Color.magenta, 10);

            // relative motion
            //transform.Translate(targetX, targetY, targetZ, Space.World);

            // transform.rotation = newrot;

            Quaternion oldrot   = transform.rotation;
            Quaternion newrot   = new Quaternion(targetXrot, targetYrot, targetZrot, targetWrot);
            float      turnrate = 60; // heuristically determined smooth rotation rate, tweak as desired

            // Rotate the GameObject but in a gradual way
            transform.rotation = Quaternion.RotateTowards(oldrot, newrot, turnrate * Time.deltaTime);
            //transform.rotation = newrot; // this rotates immediately

            // display x,y,z on attached canvas GameObject
            if (myText != null)
            {
                myText.text =
                    oldx + Environment.NewLine +
                    oldy + Environment.NewLine +
                    oldz;
            }

            // hasUpdate = false;
        }
    }