// Use this for initialization
 void Start()
 {
     circleCollider = GetComponent <CircleCollider2D>();
 }
Exemple #2
0
 // Use this for initialization
 void Start()
 {
     tr           = GetComponent <Transform>();
     initPosition = tr.position;
     cc           = GetComponent <CircleCollider2D>();
 }
 // Start is called before the first frame update
 void Start()
 {
     spriteRenderer   = GetComponent <SpriteRenderer>();
     circleCollider2D = GetComponent <CircleCollider2D>();
 }
 private void Awake()
 {
     manager          = GameObject.Find("GameManager").GetComponent <Manager>();
     circleCollider2D = gameObject.GetComponent <CircleCollider2D>();
     bombText         = gameObject.GetComponentInChildren <TextMesh>();
 }
Exemple #5
0
        public static void ApplyColliderInfoToTile(Tile tile, ColliderInfo colliderInfo)
        {
            if (tile == null || colliderInfo == null)
            {
                return;
            }

            CollisionType collisionType = colliderInfo.CollisionType;

            switch (collisionType)
            {
            case CollisionType.Box:
            {
                BoxCollider2DInfo info     = colliderInfo as BoxCollider2DInfo;
                BoxCollider2D     collider = tile.GetComponent(typeof(BoxCollider2D)) as BoxCollider2D;
                if (info != null && collider != null)
                {
                    collider.size = info.Size;

#if UNITY_5_0
                    collider.offset = info.Center;
#else
                    collider.center = info.Center;
#endif
                }
                break;
            }

            case CollisionType.Circle:
            {
                CircleCollider2DInfo info     = colliderInfo as CircleCollider2DInfo;
                CircleCollider2D     collider = tile.GetComponent(typeof(CircleCollider2D)) as CircleCollider2D;
                if (info != null && collider != null)
                {
#if UNITY_5_0
                    collider.offset = info.Center;
#else
                    collider.center = info.Center;
#endif

                    collider.radius = info.Radius;
                }
                break;
            }

            case CollisionType.Polygon:
            {
                PolygonCollider2DInfo info     = colliderInfo as PolygonCollider2DInfo;
                PolygonCollider2D     collider = tile.GetComponent(typeof(PolygonCollider2D)) as PolygonCollider2D;
                if (info != null && collider != null)
                {
                    collider.pathCount = info.PathCount;
                    collider.points    = info.Points;
                }
                break;
            }

            default:
                break;
            }
        }
Exemple #6
0
 // Start is called before the first frame update
 void Start()
 {
     _rb  = GetComponent <Rigidbody2D>();
     _col = GetComponent <CircleCollider2D>();
 }
 // Use this for initialization
 void Start()
 {
     myRigidBody = GetComponent <Rigidbody2D>();
     myHead      = GetComponent <CircleCollider2D>();
     myAnimator  = GetComponent <Animator>();
 }
        void Update()
        {
      #if UNITY_EDITOR
            OnValidate();
      #endif

            Mesh mesh = new Mesh();

            PolygonCollider2D _polygon2d = gameObject.GetComponent <PolygonCollider2D>();
            BoxCollider2D     _box2d     = gameObject.GetComponent <BoxCollider2D>();
            CircleCollider2D  _circle2d  = gameObject.GetComponent <CircleCollider2D>();
            EdgeCollider2D    _edge2d    = gameObject.GetComponent <EdgeCollider2D>();

            if (_polygon2d)
            {
                // points are alredy rotated :)
                int       pointCount = _polygon2d.GetTotalPointCount();
                Vector2[] points     = _polygon2d.points;

                Vector3[] vertices = new Vector3[pointCount];
                for (int j = 0; j < pointCount; j++)
                {
                    Vector2 actual = points[j];
                    vertices[j] = new Vector3(actual.x, actual.y, 0);
                }
                Triangulator tr        = new Triangulator(points);
                int[]        triangles = tr.Triangulate();
                mesh.vertices  = vertices;
                mesh.triangles = triangles;
            }

            if (_box2d)
            {
                mesh.vertices = GetBoxCorners(_box2d);
                int[] triangles = { 0, 1, 2, 1, 3, 2 };
                mesh.triangles = triangles;
            }

            if (_circle2d)
            {
                float scale = 1f / 16f;

                Vector3[] vertices = new Vector3[16];
                Vector2[] points   = new Vector2[16];
                for (int j = 0; j < 16; j++)
                {
                    float x = (_circle2d.offset.x +
                               Mathf.Cos(scale * j * 2 * Mathf.PI) * _circle2d.radius) *
                              _circle2d.transform.localScale.x;
                    float y = (_circle2d.offset.y +
                               Mathf.Sin(scale * j * 2 * Mathf.PI) * _circle2d.radius) *
                              _circle2d.transform.localScale.y;
                    points[j]   = new Vector2(x, y);
                    vertices[j] = new Vector3(x, y, 0);
                }
                Triangulator tr        = new Triangulator(points);
                int[]        triangles = tr.Triangulate();
                mesh.vertices  = vertices;
                mesh.triangles = triangles;
            }

            if (_edge2d)
            {
                Debug.LogWarning("EdgeCollider2D is not supported");
            }

            _mf.mesh = mesh;
        }
 // Use this for initialization
 void Start()
 {
     collider  = GetComponent <CircleCollider2D>();
     maxDist   = transform.localScale.x * collider.radius * 2;
     startTime = Time.time;
 }
Exemple #10
0
 private void Start()
 {
     circleCollider2D        = GetComponent <CircleCollider2D>();
     circleCollider2D.radius = range;
     controller = GetComponentInChildren <UselessPigsController>();
 }
Exemple #11
0
 public static void SetPlayer(GameObject newPlayer)
 {
     playerOne         = newPlayer;
     playerOneRb       = newPlayer.GetComponent <Rigidbody2D>();
     interactionRadius = newPlayer.transform.GetChild(0).GetComponent <CircleCollider2D>();
 }
 // Start is called before the first frame update
 void Start()
 {
     cc        = gameObject.GetComponent <CircleCollider2D>();
     cc.radius = 7.5f;
 }
Exemple #13
0
 // Use this for initialization
 void Start()
 {
     player = (PlayerController)FindObjectOfType(typeof(PlayerController));
     circle = (CircleCollider2D)collider2D;
 }
Exemple #14
0
 void Start()
 {
     rb                     = GetComponent <Rigidbody2D>();
     circleCollider         = GetComponent <CircleCollider2D>();
     circleCollider.enabled = false;
 }
Exemple #15
0
 void Start()
 {
     sphereCollider  = GetComponent <CircleCollider2D>();
     sphereTransform = GetComponent <Transform>();
     alarmaEncendida = false;
 }
Exemple #16
0
 // Use this for initialization
 void Start()
 {
     spriteRenderer = GetComponent <SpriteRenderer> ();
     BallCollider   = GetComponent <CircleCollider2D> ();
     scoringSystem  = GameObject.FindGameObjectWithTag("ScoringSystem");
 }
    void Update()
    {
        //Get the current speed, just to show it in the inspector
        currentSpeed = rb.velocity.magnitude;

        //Check for future collisions with obstacles
        ContactFilter2D filter = new ContactFilter2D();

        filter.SetLayerMask(obstacleLayer);
        List <RaycastHit2D> results = new List <RaycastHit2D>();

        bc.Cast(rb.velocity, filter, results, rb.velocity.magnitude);

        Vector2 desiredVel;

        //If we are going to collide, we need to steer around it.
        if (results.Count > 0)
        {
            //Find the hit point and the direction of the wall where the hit occurred
            RaycastHit2D hit  = results[0];
            Vector2      wall = new Vector2(hit.normal.y, -hit.normal.x);

            //Decide whether to go right or left depending on what point was hit
            Vector2 forward = rb.velocity.normalized;
            Vector2 right   = new Vector2(forward.y, -forward.x);
            float   side    = Vector2.Dot(hit.point - hit.centroid, right);
            if (side < 0)
            {
                wall = -wall;
            }

            //We need to find the point along the wall
            // that is maxSpeed away from the current position.
            // So we find the intersection of a circle of radius maxSpeed
            // with a ray along the wall.
            //We have to shoot the ray from outside the circle toward
            // the centroid. Otherwise it considers the collision to
            // have occurred immediately.

            //Set up the circle
            CircleCollider2D cc = GetComponent <CircleCollider2D>();
            cc.enabled = true;
            cc.radius  = maxSpeed;

            //Cast the ray
            RaycastHit2D intersection =
                Physics2D.Raycast(hit.centroid + maxSpeed * wall, -wall, 2 * maxSpeed, carLayer);
            Debug.DrawRay(hit.centroid + maxSpeed * wall, -wall * 2 * maxSpeed, Color.red);
            cc.enabled = false;

            //The desired velocity is toward that intersection point.
            desiredVel = intersection.point - (Vector2)transform.position;
        }
        else
        {
            //Calculate the seek steering direction
            Vector2 toTarget = target.position - transform.position;
            float   distance = toTarget.magnitude;
            float   speed;
            if (distance < maxSpeed) //if we will reach in under 1 second
            {
                speed = distance;
            }
            else
            {
                speed = maxSpeed;
            }
            desiredVel = toTarget / toTarget.magnitude * speed;
        }
        Vector2 seekVelocity = desiredVel - rb.velocity;

        //Let's draw the vectors
        Debug.DrawRay(transform.position, rb.velocity, Color.white);
        Debug.DrawRay(transform.position, desiredVel, Color.magenta);
        Debug.DrawRay(transform.position, seekVelocity, Color.green);
        Debug.DrawRay(transform.position + (Vector3)rb.velocity, seekVelocity, Color.green);

        //Apply the force
        Vector2 force = seekVelocity / maxSpeed * maxForce;

        rb.AddForce(force);
    }
Exemple #18
0
 void Start()
 {
     cam            = Camera.main;
     rb             = GetComponent <Rigidbody2D>();
     circleCollider = GetComponent <CircleCollider2D>();
 }
Exemple #19
0
 private void Awake()
 {
     playerCam              = FindObjectOfType <PlayerCamera>();
     circleCollider         = GetComponent <CircleCollider2D>();
     circleCollider.enabled = false;
 }
Exemple #20
0
 // Use this for initialization
 void Start()
 {
     player   = GameDirector.Get().player;
     circle2d = GetComponent <CircleCollider2D>();
     col2d    = player.GetComponent <Collider2D>();
 }
Exemple #21
0
 private void Awake()
 {
     _Feet = GetComponent <CircleCollider2D>();
 }
Exemple #22
0
 private void Awake()
 {
     myRigidbody2D     = GetComponent <Rigidbody2D>();
     myTestGroundCheck = GetComponent <CircleCollider2D>();
 }
Exemple #23
0
 // Start is called before the first frame update
 void Start()
 {
     bitScript = GetComponentInParent <BitBehaviour>();
     circle    = GetComponent <CircleCollider2D>();
 }
Exemple #24
0
 //initialize fields
 private new void Start()
 {
     projCollider = GetComponent <CircleCollider2D>();
 }
Exemple #25
0
        public static bool IsTileColliderEqualsToColliderInfo(Tile tile, ColliderInfo colliderInfo)
        {
            if (tile == null || colliderInfo == null)
            {
                return(false);
            }
            switch (colliderInfo.CollisionType)
            {
            case CollisionType.Box:
            {
                BoxCollider2D     collider = tile.GetComponent(typeof(BoxCollider2D)) as BoxCollider2D;
                BoxCollider2DInfo info     = colliderInfo as BoxCollider2DInfo;
                if (collider == null || info == null)
                {
                    return(false);
                }
#if UNITY_5_0
                if (info.Center == collider.offset && info.Size == collider.size)
#else
                if (info.Center == collider.center && info.Size == collider.size)
#endif
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            case CollisionType.Circle:
            {
                CircleCollider2D     collider = tile.GetComponent(typeof(CircleCollider2D)) as CircleCollider2D;
                CircleCollider2DInfo info     = colliderInfo as CircleCollider2DInfo;
                if (collider == null || info == null)
                {
                    return(false);
                }
#if UNITY_5_0
                if (collider.offset == info.Center && collider.radius == info.Radius)
#else
                if (collider.center == info.Center && collider.radius == info.Radius)
#endif
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            case CollisionType.Polygon:
            {
                PolygonCollider2D     collider = tile.GetComponent(typeof(PolygonCollider2D)) as PolygonCollider2D;
                PolygonCollider2DInfo info     = colliderInfo as PolygonCollider2DInfo;
                if (collider == null || info == null)
                {
                    return(false);
                }

                if (collider.pathCount == info.PathCount)
                {
                    for (int i = 0; i < collider.pathCount; ++i)
                    {
                        if (collider.points[i] != info.Points[i])
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            default:
                return(true);
            }
        }
Exemple #26
0
 private void Awake()
 {
     col    = GetComponent <CircleCollider2D>();
     action = GetComponent <DefendAction>();
 }
Exemple #27
0
 // Use this for initialization
 void Start()
 {
     explosionRadius = gameObject.GetComponent <CircleCollider2D>();
 }
 private void Awake()
 {
     sensorColl = GetComponent <CircleCollider2D>();
 }
 private void Start()
 {
     collider2D = GetComponent <CircleCollider2D>();
 }
Exemple #30
0
 private void Start()
 {
     rigidBody      = GetComponent <Rigidbody2D>();
     circleCollider = GetComponent <CircleCollider2D>();
     cam            = Camera.main;
 }