Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        //Debug
        //Scales Debug circle to the size of the actual circle drawn
        float maxDimension = Mathf.Max(transform.lossyScale.x, transform.lossyScale.y);
        Color c            = new Color(0, 0, .5f, .125f);

        if (triggering)
        {
            c = new Color(1f, 0, 0, .125f);
        }
        PlayerDebug.DrawCircle(transform.position, circleCollider.radius * maxDimension, c);

        foreach (SquadUnit su in units)
        {
            if (Vector2.Distance(su.unit.transform.position, transform.position) < .1f)
            {
                su.unit.GetComponent <Rigidbody2D>().velocity = Vector2.zero;
                su.unit.transform.position = transform.position;
                if (isServer)
                {
                    su.unit.GetComponent <CharacterMovement>().speedMultiplier = 0;
                    su.unit.GetComponent <Rigidbody2D> ().simulated            = false;
                }
            }
        }
    }
Exemple #2
0
 private void OnGUI()
 {
     if (debug != null)
     {
         PlayerDebug.DrawQuad(debug, Color.red);
     }
 }
    // Update is called once per frame
    protected override void Update()
    {
        base.Update();

        timer -= Time.deltaTime;
        Vector3 pos = transform.position;

        //Make new wander point after getting close enough to previous point or running out of time
        if (Vector2.Distance(target.position, pos) < maxDistance || timer <= 0)
        {
            //Raycast forward so agent may eventually move from wall (wander target won't go past wall)
            RaycastHit2D raycast = Physics2D.Raycast(pos, transform.up, circleDistance);
            PlayerDebug.DrawRay(pos, transform.up * circleDistance, Color.blue, .5f);


            //Rigidbody will be null if nothing hit
            float dist = (raycast.rigidbody == null) ? circleDistance : raycast.distance;
            circlePosition = transform.position + transform.up * dist;


            bool position_within_bounds = false;
            while (!position_within_bounds)
            {
                target.position = (Vector3)(Random.insideUnitCircle * circleRadius + circlePosition);
                if (Physics2D.Raycast(pos, target.position - transform.position, Vector3.Distance(target.position, transform.position)).rigidbody == null)
                {
                    position_within_bounds = true;
                    print("found a position");
                }
            }

            timer = maxTime;
        }
    }
 // Update is called once per frame
 protected virtual void Update()
 {
     PlayerDebug.DrawRay(transform.position + Vector3.back, DirectionFacing * .75f, new Color(1f, 0, 0, 1f));
     if (animator != null)
     {
         animator.SetFloat("MoveSpeed", rb.velocity.magnitude);
         animator.SetBool("Stopping", direction.magnitude == 0);
     }
 }
    void LateUpdate()
    {
        //Outer circle
        Color outerColor = new Color(1f, 0, 0, .25f * timer / maxTime);

        PlayerDebug.DrawCircle(circlePosition, circleRadius, outerColor);
        //Inner Circle
        PlayerDebug.DrawLine(transform.position, target.position, Color.red);
        PlayerDebug.DrawCircle(target.position, maxDistance / 2f, Color.red);
    }
Exemple #6
0
 void LateUpdate()
 {
     if (points.Count >= 2)
     {
         for (int i = 1; i < points.Count; i++)
         {
             PlayerDebug.DrawLine(points[i - 1].transform.position, points[i].transform.position, Color.blue);
         }
         PlayerDebug.DrawLine(points[0].transform.position, points[points.Count - 1].transform.position, Color.cyan);
     }
 }
Exemple #7
0
    void FixedUpdate()
    {
        rb.AddForce(transform.up * Mathf.Min(maxAcceleration, acceleration * maxAcceleration));
        PlayerDebug.DrawRay(transform.position, transform.up, Color.white);
        //This clamping is not actually accurate as the addForce will increase the speed for a frame after
        //If you disable force when speed is over max speed that creates hysteresis
        //A correct force reduction is more complicated
        rb.velocity = Vector2.ClampMagnitude(rb.velocity, maxSpeed);

        TurnToTarget();
    }
Exemple #8
0
    void Awake()
    {
        instance = this;
        verts    = new List <Vector3>();
        colors   = new List <Color>();
        times    = new List <float>();

        circleCenters = new List <Vector3>();
        circleRadii   = new List <float>();
        circleColors  = new List <Color>();
    }
    void DrawBoundary()
    {
        if (!selected)
        {
            return;
        }
        Color color = Color.red;

        PlayerDebug.DrawRay(transform.position + new Vector3(deadzone, -5f, 1f), Vector3.up * 10f, color);
        PlayerDebug.DrawRay(transform.position + new Vector3(-deadzone, -5f, 1f), Vector3.up * 10f, color);
        selected = false;
    }
Exemple #10
0
    void LateUpdate()
    {
        Vector3 halfConeRight = (Quaternion.Euler(0, 0, maxAngle * .5f) * transform.up).normalized;
        Vector3 halfConeLeft  = (Quaternion.Euler(0, 0, maxAngle * -.5f) * transform.up).normalized;

        Vector3 p1 = transform.position + halfConeLeft * maxDistance;
        Vector3 p2 = transform.position + halfConeRight * maxDistance;

        PlayerDebug.DrawLine(transform.position, p1, new Color(0, 0, 1f, .25f));
        PlayerDebug.DrawLine(transform.position, p2, new Color(0, 0, 1f, .25f));
        //Makes a triangle, not technically the cone that is being used, but helps to visualize it
        //PlayerDebug.DrawLine(p1, p2,new Color(0,0,1f,.25f));
    }
Exemple #11
0
    void LateUpdate()
    {
        if (points.Count >= 2)
        {
            for (int i = 1; i < points.Count; i++)
            {
                PlayerDebug.DrawLine(points[i - 1].transform.position, points[i].transform.position, path_color);
            }

            if (looping)
            {
                PlayerDebug.DrawLine(points[0].transform.position, points[points.Count - 1].transform.position, path_color * 2f);
            }
        }
    }
Exemple #12
0
    void Awake()
    {
                #if UNITY_EDITOR
        EditorApplication.playmodeStateChanged += OnStateChange;
                #endif
        instance  = this;
        verts     = new List <Vector3>();
        colors    = new List <Color>();
        lineTimes = new List <float>();

        circleCenters  = new List <Vector3>();
        circleRadii    = new List <float>();
        circleColors   = new List <Color>();
        circleSegments = new List <int>();
        circleTimes    = new List <float>();
    }
Exemple #13
0
    // Update is called once per frame
    void Update()
    {
        if (targets.Count == 0)
        {
            DrawBoundary();
            return;
        }

        //Get average positions of all transforms
        Vector3 averagePosition = new Vector3();

        for (int i = 0, targetsCount = targets.Count; i < targetsCount; i++)
        {
            averagePosition += targets [i].position;
        }
        averagePosition *= 1f / targets.Count;

        //Get max and min x to set camera projection size if necessary
        //
        //

        if (selected)
        {
            Vector3 zPosition = averagePosition;
            zPosition.z = transform.position.z + .5f;
            PlayerDebug.DrawRay(zPosition + Vector3.down * .5f, Vector3.up, Color.blue);
            PlayerDebug.DrawRay(zPosition + Vector3.left * .5f, Vector3.right, Color.blue);
        }

        //Push camera if average position moves outside of deadzone
        float x        = averagePosition.x - transform.position.x;
        float distance = Mathf.Abs(x);

        if (distance > deadzone)
        {
            float   direction = Mathf.Sign(x);
            Vector3 pos       = transform.position;
            pos.x = averagePosition.x - deadzone * direction;

            //transform.position = pos;
            transform.position = Vector3.Lerp(transform.position, pos, Time.deltaTime * moveSpeed);
        }

        DrawBoundary();
    }
Exemple #14
0
    // Update is called once per frame
    void Update()
    {
        float xPart = width / (xSegments);
        float yPart = height / (ySegments);

        for (int i = 0; i < xSegments + 1; i++)
        {
            Vector3 v1 = positionOffset + new Vector3(xPart * (i), 0);
            Vector2 v2 = positionOffset + new Vector3(xPart * (i + 1), height);
            PlayerDebug.DrawLine(v1, v2, color);
        }
        for (int j = 0; j < ySegments + 1; j++)
        {
            Vector3 v1 = positionOffset + new Vector3(xPart * j / ySegments, yPart * j);
            Vector3 v2 = positionOffset + new Vector3(width + xPart * j / ySegments, yPart * (j));
            PlayerDebug.DrawLine(v1, v2, color);
        }
    }
    protected override void OnDrawGizmos()
    {
        //base.OnDrawGizmos();

        if (!enabled || target == null)
        {
            return;
        }
        //Outer circle
        Color outerColor = new Color(1f, 0, 0, .25f * timer / maxTime);

        Gizmos.color = outerColor;
        Gizmos.DrawSphere(circlePosition, circleRadius);
        PlayerDebug.DrawCircle(circlePosition, circleRadius, outerColor);

        //Inner circle
        Gizmos.color = Color.red;
        Gizmos.DrawSphere(target.position, maxDistance / 2f);
    }
 void LateUpdate()
 {
     PlayerDebug.DrawCircle(transform.position, 0.25f, Color.blue);
 }
 void LateUpdate()
 {
     PlayerDebug.DrawLine(transform.position, my_path.points[path_index].position, Color.red);
 }
	void Update(){
		PlayerDebug.DrawRay (transform.position, transform.up * indicatorLineLength, Color.white);
		PlayerDebug.DrawCircle(transform.position, GetComponent<CircleCollider2D>().radius,agentColor);
	}
Exemple #19
0
 void LateUpdate()
 {
     PlayerDebug.DrawLine(target.position, targetPosition, Color.red);
     PlayerDebug.DrawCircle(targetPosition, .125f, Color.red);
 }
Exemple #20
0
 private void SearchPlayerDebug()
 {
     _playerDebug = GameObject.Find("DebugCanvas").GetComponent <PlayerDebug>();
 }