Exemplo n.º 1
0
    private bool onRightWall()
    {
        Vector3 size = GetComponent <Collider2D> ().bounds.size;

        Vector2 lineStart    = new Vector2(this.transform.position.x + (size.x / 2) + 0.1f, this.transform.position.y + (size.y / 4));
        Vector2 searchVector = new Vector2(this.transform.position.x + (size.x / 2) + 0.1f, this.transform.position.y - (size.y / 2) + 0.1f);

        RaycastHit2D[] hit = Physics2D.LinecastAll(lineStart, searchVector);
        Debug.DrawLine(lineStart, searchVector, Color.red);

        //loop through all hits and return first object that isn't self
        foreach (RaycastHit2D hi in hit)
        {
            if (hi.transform != transform)
            {
                if (hi.transform.tag != "Player" && hi.transform.tag != "Weapon" && hi.transform.tag != "PlayerMisc")
                {
                    //if (!hi.transform.GetComponent<PlayerController> ().movementPause) {
                    return(true);
                    //}
                }                 //else {
                                  //	return true;
                                  //}
            }
        }

        return(false);
    }
Exemplo n.º 2
0
    private void DrawPreviewLines(Vector2 pointA, Vector2 pointB, Vector2 a2bUnit, Vector2 b2aUnit, CompositeTouchArea t, int index)
    {
        RaycastHit2D[] a2bHits = Physics2D.LinecastAll(pointA, pointB);
        RaycastHit2D[] b2aHits = Physics2D.LinecastAll(pointB, pointA);

        RaycastHit2D[] orderedHits = a2bHits.Concat(b2aHits).ToArray();

        if (orderedHits.Length == 0)
        {
            return;
        }

        Array.Sort(orderedHits, (a, b) => a.point[index] < b.point[index] ? -1 : a.point[index] > b.point[index] ? 1 : 0);

        for (int i = 0, j = 1; j < orderedHits.Length; i++, j++)
        {
            Vector2 aTolerance = orderedHits[i].point + a2bUnit * previewPointTolerance;
            Vector2 bTolerance = orderedHits[j].point + b2aUnit * previewPointTolerance;

            bool aOverlaps = t.OverlapPoint(aTolerance);
            bool bOverlaps = t.OverlapPoint(bTolerance);
            if (aOverlaps && bOverlaps)
            {
                Handles.color = Color.green;
                Handles.DrawLine(orderedHits[i].point, orderedHits[j].point);
            }
            else if (aOverlaps || bOverlaps)
            {
                Handles.color = Color.red;
                Handles.DrawLine(orderedHits[i].point, orderedHits[j].point);
                Handles.DrawSolidDisc(orderedHits[i].point, Vector3.forward, 0.01f);
                Handles.DrawSolidDisc(orderedHits[j].point, Vector3.forward, 0.01f);
            }
        }
    }
Exemplo n.º 3
0
    private bool interact()
    {
        Vector2 start     = transform.position;
        Vector2 end       = start + getInteractDirection() * interactDistance;
        int     layerMask = 1 << interactableLayerMask;

        RaycastHit2D[] hitObjects = Physics2D.LinecastAll(start, end, layerMask);

        if (hitObjects.Length > 0)
        {
            // Get all objects in front of the player with the layerMask
            foreach (RaycastHit2D hit in hitObjects)
            {
                // Get the first hit object in the list which has an Interactable script and interact with it
                Interactable hitInteractable = hit.transform.GetComponent <Interactable>();

                if (hitInteractable)
                {
                    hitInteractable.Interact();
                    return(true);
                }
            }
        }
        return(false);
    }
Exemplo n.º 4
0
    private void Update()
    {
        Vector2 currentPosition = new Vector2(transform.position.x, transform.position.y);
        Vector2 newPosition     = currentPosition + velocity * Time.deltaTime;

        RaycastHit2D[] hits = Physics2D.LinecastAll(currentPosition, newPosition);

        foreach (RaycastHit2D hit in hits)
        {
            GameObject other = hit.collider.gameObject;
            if (other.CompareTag("Solid"))
            {
                Destroy(gameObject);
                break;
            }

            if (other.CompareTag("PlayerBody"))
            {
                playerscript.DamagePlayer(1);
                Destroy(gameObject);
                break;
            }
        }
        transform.position = newPosition;
    }
Exemplo n.º 5
0
    /// <summary>
    /// 判断一个对象是否在自己的可视范围内
    /// </summary>
    /// <returns></returns>
    protected bool isInSight(RavenEntity entity)
    {
        float angleBetweenEntity = Vector2.Angle(owner.transform.up, entity.Pos - owner.Pos);

        //Debug.Log("相隔的角度是"+angleBetweenEntity);
        //如果在实体的视锥体范围内
        if (angleBetweenEntity < this.angle)
        {
            float sqrtDistanceBetweenEntity = (entity.Pos - this.owner.Pos).sqrMagnitude;

            if (sqrtDistanceBetweenEntity < (distance * distance))
            {
                //在视锥体的视野范围内

                hits = Physics2D.LinecastAll(owner.Pos, entity.Pos, ~(1 << 0));

                if (hits.Length >= 1)
                {
                    if (hits[1].collider.tag == "Wall")
                    {
                        return(false);
                    }
                    else
                    {
                        return(true);
                    }
                }
            }
        }

        return(false);
    }
    void DestroyLine()
    {
        ArrayList b         = new ArrayList();
        int       layerMask = 1 << LayerMask.NameToLayer("Ball");

        RaycastHit2D[] fixedBalls = Physics2D.LinecastAll(transform.position + Vector3.left * 10, transform.position + Vector3.right * 10, layerMask);
        int            i          = 0;

        foreach (RaycastHit2D item in fixedBalls)
        {
            if (!findInArray(b, item.collider.gameObject))
            {
                b.Add(item.collider.gameObject);
            }
        }


        if (b.Count >= 0)
        {
            mainscript.Instance.ComboCount++;
            mainscript.Instance.destroy(b);
        }

        mainscript.Instance.StartCoroutine(mainscript.Instance.destroyAloneBall());
    }
Exemplo n.º 7
0
    protected virtual void UpdateGroundedStatus()
    {
        // Look through all the colliders touching the ground check, and see if any are walkable
        List <GameObject> walkables = new List <GameObject>
                                      (
            from Collider2D coll in groundCheck.collidersTouching
            where groundLayers.Contains(coll.gameObject.layer) ||
            groundTags.Contains(coll.gameObject.tag)
            select coll.gameObject
                                      );

        if (walkables.Count == 0)
        {
            grounded = false;
            return;
        }

        // If so, linecast down to the ground check. Then look through the hits to see if any are among the
        // walkables its touching.
        Vector3 justBelowCheck = groundCheck.pos + Vector3.down;

        RaycastHit2D[] hits = Physics2D.LinecastAll(transform.position, justBelowCheck);

        foreach (RaycastHit2D hit in hits)
        {
            grounded = walkables.Contains(hit.transform.gameObject);

            if (grounded)
            {
                return;
            }
        }
    }
Exemplo n.º 8
0
    private ContextMap TargetPursuingMap()
    {
        ContextMap map = new ContextMap(_steer.DirectionsCount);

        Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, VisionRadius, _target_mask);

        foreach (Collider2D collider in colliders)
        {
            if (TargetIdentification(collider))
            {
                RaycastHit2D[] hits     = Physics2D.LinecastAll(transform.position, collider.transform.position);
                float          distance = Vector2.Distance(transform.position, hits[hits.Length - 1].point);

                float weight = (VisionRadius - distance) / VisionRadius;
                if (weight < 0)
                {
                    continue;
                }

                map.AddInterestToVector(collider.transform.position - transform.position, weight);
            }
        }

        return(map);
    }
Exemplo n.º 9
0
    private ContextMap ObstructionAvoidanceMap()
    {
        ContextMap map = new ContextMap(_steer.DirectionsCount);

        Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, VisionRadius, _danger_mask);
        foreach (Collider2D collider in colliders)
        {
            if (DangerIdentification(collider))
            {
                RaycastHit2D[] hits     = Physics2D.LinecastAll(transform.position, collider.transform.position);
                float          distance = Vector2.Distance(transform.position, hits[hits.Length - 1].point);

                float weight = (VisionRadius - distance) / VisionRadius;
                if (weight < 0)
                {
                    continue;
                }

                Vector2 danger = collider.transform.position - transform.position;
                map.AddInterestToVectorWithDesirableDot(-danger, weight, 0.65f);
                map.AddDangerToVectorWithThreshold(danger, weight, 0.65f);
            }
        }

        return(map);
    }
Exemplo n.º 10
0
    // Update is called once per frame
    void Update()
    {
        if (!player || gameManager.finished)
        {
            return;
        }

        //	Debug.DrawRay(transform.position, player.gameObject.transform.position - transform.position);
        RaycastHit2D[] hit = Physics2D.LinecastAll(transform.position, player.gameObject.transform.position, 1 << LayerMask.NameToLayer("entity") | 1 << LayerMask.NameToLayer("wall"));

        foreach (var h in hit)
        {
            if (h.collider.tag == "Player")
            {
                seePlayer = true;
                break;
            }
            if (h.collider.gameObject.tag == "Untagged")
            {
                seePlayer = false;
                break;
            }
        }

        if (folow && canShoot && seePlayer)
        {
            entity.fireWeapon(transform, Entity.Target.Player);
            canShoot = false;
        }
        StartCoroutine(enemyCanShoot());
    }
Exemplo n.º 11
0
        private void Reveal(HexTile tileArrivedAt)
        {
            // Get all hex tiles that are in range
            List <HexTile> tiles = hexGrid.GetTilesInRange(tileArrivedAt, 3);

            List <HexTile> visible = new List <HexTile>();

            // Test for obstacles
            foreach (HexTile tile in tiles)
            {
                Collider2D self = tile.Collider;

                // Should do this while we're travelling
                var hits = Physics2D.LinecastAll(tileArrivedAt.transform.position, tile.transform.position, 1 << LayerMask.NameToLayer("Traversable")).ToList();

                if (hits.Where(hit => hit.collider.gameObject.GetComponent <HexTile>().BlockLos&& hit.collider != self).ToArray().Length == 0)
                {
                    visible.Add(tile);
                }
            }


            // Reveal remainder
            foreach (HexTile tile in visible)
            {
                ToggleTileAndActors(tile, 1.0f);
                tile.Discover();
            }

            // Store currently visible tiles
            this.currentlyVisible = visible;
        }
Exemplo n.º 12
0
    /**
     * @method PlotUntilCollision
     * @param Vector3 From The location to plot from
     * @param Vector2 Dir The direction the plotting should occur
     * @param int MaxDepth The maximum number of plots that can be added
     * @return Vector2[]
     * Create a set of positions that mark out the points that should be plotted
     */
    private Vector2[] PlotUntilCollision(Vector2 From, Vector2 Dir, int MaxDepth)
    {
        List <Vector2> plots          = new List <Vector2>();
        bool           hasHitCollider = false;
        int            cDepth         = 0;

        while (!hasHitCollider && cDepth < MaxDepth)
        {
            RaycastHit2D[] hits = Physics2D.LinecastAll(From, From + Dir);
            foreach (RaycastHit2D hit in hits)
            {
                if (hit.collider.isTrigger)
                {
                    continue;
                }
                if (hit.transform.gameObject != this.Movable.GetTransform().gameObject)
                {
                    hasHitCollider = true;
                    break;
                }
            }
            if (hasHitCollider)
            {
                break;
            }
            plots.Add(From + Dir);
            cDepth++;
            From = From + Dir;
        }
        return(plots.ToArray());
    }
Exemplo n.º 13
0
    public static GameObject SelectedObject()
    {
        Vector3 clickedPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);                                                               //Store out clicked position

        hits = Physics2D.LinecastAll(new Vector3(clickedPos.x, clickedPos.y, -2), new Vector3(clickedPos.x, clickedPos.y, 5), clickableLayers); //Cast ray at the world space the mouse is at

        if (hits.Length > 0)                                                                                                                    //Only function if we actually hit something
        {
            int topHit    = 0;                                                                                                                  //Set our top hit to a default of the first index in our "hits" array, in case there are no others
            int preVal    = hits[0].transform.GetComponent <SpriteRenderer>().sortingLayerID;                                                   //Store the SortingLayerID of the first object in the array, so it doesn't get skipped
            int preSubVal = hits[0].transform.GetComponent <SpriteRenderer>().sortingOrder;                                                     //Store the SortingOrder value of the first object in the array, in case it needs to be compared to

            for (int arrayID = 1; arrayID < hits.Length; arrayID++)                                                                             //Loop for every extra item the raycast hit
            {
                int curVal = hits[arrayID].transform.GetComponent <SpriteRenderer>().sortingLayerID;                                            //Store SortingLayerID of the current item in the array being accessed

                if (curVal < preVal)                                                                                                            //If the SortingLayerID of the current array item is lower than the previous lowest
                {
                    preVal    = curVal;                                                                                                         //Set the "Previous Value" to the current one since it's lower, as it will become the "Previous Lowest" on the next loop
                    topHit    = arrayID;                                                                                                        //Set our topHit with the Array Index value of the current closest Array item, since it currently has the highest/closest SortingLayerID
                    preSubVal = hits[arrayID].transform.GetComponent <SpriteRenderer>().sortingOrder;                                           //Store SortingOrder value of the current closest object, for comparison next loop if we end up going to the "else if"
                }
                else if ((curVal == preVal) && (hits[arrayID].transform.GetComponent <SpriteRenderer>().sortingOrder > preSubVal))              //If SortingLayerID are the same, then we need to compare SortingOrder. If the SortingOrder is lower than the one stored in the previous loop, then update values
                {
                    topHit    = arrayID;
                    preSubVal = hits[arrayID].transform.GetComponent <SpriteRenderer>().sortingOrder;
                }
            }
            return(hits[topHit].transform.gameObject);
        }
        return(null);
    }
Exemplo n.º 14
0
    private void Update()
    {
        Vector2 currentPosition = new Vector2(transform.position.x, transform.position.y);
        Vector2 newPosition     = currentPosition + speed * Time.deltaTime;

        RaycastHit2D[] hits = Physics2D.LinecastAll(currentPosition, newPosition);

        foreach (RaycastHit2D hit in hits)
        {
            if (hit.collider.GetComponent <IDamagable>() != null || hit.collider.gameObject == shooter)
            {
                if (!hit.collider.CompareTag("Enemy"))
                {
                    hit.collider.GetComponent <IDamagable>().Hurt(damage);
                    Destroy(gameObject);
                }
            }
            if (hit.collider.tag == "Border" || hit.collider.tag == "Enemy")
            {
                continue;
            }
            else
            {
                Destroy(gameObject);
                break;
            }
        }

        transform.position = newPosition;
    }
Exemplo n.º 15
0
    public override bool Cast()
    {
        bool wasCast = false;

        effectAlpha = 1f;

        Vector2 mousePosition  = player.GetComponent <ClickHandler>().getMousePosition();
        Vector2 playerPosition = player.GetComponent <Rigidbody2D>().position;

        RaycastHit2D[] hits = Physics2D.LinecastAll(playerPosition, mousePosition);
        foreach (RaycastHit2D hit in hits)
        {
            if (hit != null && hit.collider != null)
            {
                if (hit.collider.gameObject.GetComponent <EnemyController>() != null)
                {
                    // CombatText combatText = hit.collider.gameObject.AddComponent(typeof(CombatText)) as CombatText;
                    // combatText.text= damage.ToString();
                    CombatText.Create(hit.collider.gameObject.transform.position, 100.ToString(), false);
                    StatusText.Create(hit.collider.gameObject.transform.position, "Stunned", false);
                    hit.collider.gameObject.GetComponent <CombatTextFactory>().addCombatText("Hit Enemy with dash");
                    Debug.Log("Hit Enemy with dash");
                }
            }
        }

        player.GetComponent <Rigidbody2D>().position = mousePosition;
        DashEffect.Create(playerPosition, mousePosition);
        wasCast = true;

        Debug.Log("Cast Dash");
        return(wasCast);
    }
Exemplo n.º 16
0
    private void FindAppropriateStartPoint(Vector2 start, Vector2 end)
    {
        // If start point inside an obstacle find appropriate
        // point to start line.

        Collider2D[] cols = Physics2D.OverlapPointAll(start);
        foreach (Collider2D col in cols)
        {
            if (col.tag != "DrawLine")
            {
                RaycastHit2D[] hits       = Physics2D.LinecastAll(end, start);
                float          lineRadius = lineWidth / 2;

                foreach (RaycastHit2D hit in hits)
                {
                    if (hit.collider.tag != "DrawLine" && hit.collider == col)
                    {
                        // Add new start point in here. I don't know how to do it else.
                        Vector2 newStart = hit.point + hit.normal * lineRadius;
                        points.Add(newStart);
                        CreateCircle(newStart);
                        resetLine     = false;
                        mousePosition = GetAppropriateEndPoint(points[points.Count - 1], mousePosition);

                        return;
                    }
                }
            }
        }
    }
Exemplo n.º 17
0
    public override void Gore()
    {
        if (!CanGore)
        {
            return;
        }

        base.Gore();
        UpDownTile();
        CanGore       = false;
        Render.sprite = EmptySprite;
        Debug.Log("Hit vine");

        Vector2 startPos = transform.position;

        startPos.y += 1.29f;
        Vector2 endpos = transform.position;

        endpos.y += 10000f;
        RaycastHit2D[] hits = Physics2D.LinecastAll(startPos, endpos);

        foreach (var hit in hits)
        {
            if (hit.transform.CompareTag(ObjectTag.ClimbBlock))
            {
                _vine.StartUp(hit.transform.position.y - transform.position.y);
                break;
            }
        }
    }
Exemplo n.º 18
0
    void SetLaser()
    {
        Vector2 currentPosition = transform.position;
        Vector2 targetPosition  = target.transform.position;

        laserDraw.SetWidth(0.2f, 0.01f);
        laserDraw.SetColors(startColor, endColor);
        laserDraw.SetPosition(0, currentPosition);
        laserDraw.SetPosition(1, targetPosition);

        RaycastHit2D[] hits = Physics2D.LinecastAll(currentPosition, targetPosition, unitLayer);
        Debug.DrawLine(currentPosition, targetPosition, Color.red);

        if (hits.Length >= 1)
        {
            for (int i = 0; i < hits.Length; i++)
            {
                if (hits[i].collider.tag == "Player")
                {
                    IUnit unit = hits[i].collider.gameObject.GetComponent <IUnit>();
                    if (unit != null)
                    {
                        unit.Attacked(1);
                    }
                }
            }
        }

        Quaternion targetRotation = SetRotate(currentPosition, targetPosition);

        transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, 0.2f);
    }
Exemplo n.º 19
0
    private RaycastHit2D [] raycastDown()
    {
        Vector2 end = new Vector2(transform.position.x, transform.position.y - height);

        Debug.DrawLine(transform.position, end, Color.red, 2);
        return(Physics2D.LinecastAll(transform.position, end, 1 << LayerMask.NameToLayer("Walkable")));
    }
Exemplo n.º 20
0
    public static CharacterHealthPanelManager BasicLinecast(Vector2 start, Vector2 end, string attackingCharacterGUID)
    {
        //Linecast, looking for items on the layer "Fighting"
        RaycastHit2D[] linecastResult = Physics2D.LinecastAll(start, end, 1 << LayerMask.NameToLayer("Fighting"));

        //Create a line so that it is possible to see where the raycasts are going.
        Debug.DrawLine(start, end, Color.green, 3f);

        //Go through all linecast results and look for the health panel.
        if (linecastResult.Length != 0)
        {
            for (int i = 0; i < linecastResult.Length; i++)
            {
                //Check to make sure that the collider has a second parent.
                //If the collider has a parent and not a second parent, short-circuiting prevents an error.
                if (linecastResult[i].collider.transform.parent != null && linecastResult[i].collider.transform.parent.parent != null)
                {
                    Transform healthPanelTransform = linecastResult[i].collider.transform.parent.parent;
                    //Make sure that the character has a health panel manager and that the character is not attacking itself.
                    if (healthPanelTransform.GetComponent <CharacterHealthPanelManager> () != null && healthPanelTransform.GetComponent <CharacterBaseActionClass> ().GetCombatantID().Equals(attackingCharacterGUID) == false)
                    {
                        //Return the health panel manager if it exists.
                        return(healthPanelTransform.GetComponent <CharacterHealthPanelManager> ());
                    }
                }
            }
        }

        //In the event that none of the results had a health panel manager.
        return(null);
    }
    void Update()
    {
        Vector2 currentPosition = new Vector2(transform.position.x, transform.position.y);
        Vector2 newPosition     = currentPosition + velocity * Time.deltaTime;

        RaycastHit2D[] hits = Physics2D.LinecastAll(currentPosition + offset, newPosition + offset);

        foreach (RaycastHit2D hit in hits)
        {
            GameObject other = hit.collider.gameObject;
            if (other != wizard)
            {
                if (other.CompareTag("Walls"))
                {
                    Debug.Log("Fireball hit a Wall!");
                    Destroy(gameObject);
                    break;
                }
                if (other.CompareTag("Enemy"))
                {
                    // to remove bug multiple hit with Collider of same Enemy (and multiple TakeDamage)
                    if (enemyHit)
                    {
                        enemyHit = false;
                        //Debug.Log("Enemy hit detected by RayCast!");
                        StartCoroutine(PlayHitAnimation());
                        other.GetComponent <FirstEnemySkript>().TakeDamage(damage);
                        break;
                    }
                }
            }
        }

        transform.position = newPosition;
    }
Exemplo n.º 22
0
    public void Attack()
    {
        Vector2 end = this.transform.position;

        end.x += (isFacingRight ? 1 : -1) * attackLength;

        var hit = Physics2D.LinecastAll(this.transform.position, end, 1 << Data.ENEMY_LAYER);

        foreach (var obj in hit)
        {
            Health health = obj.collider.GetComponent <Health>();

            if (health != null)
            {
                health.TakeDamage(damage);
                if (health.IsDead())
                {
                    var level = health.LevelSys;
                    if (level != null)
                    {
                        m_levelSystem.GainExp(level.ExpWorth);
                        //print("Gained " + level.ExpWorth);
                    }
                }
            }

            //print("Hit " + obj.collider.name);
        }

        nextAttackTime = Time.time + attackTime;
    }
Exemplo n.º 23
0
    public static T BasicLinecast <T> (Vector2 start, Vector2 end)
    {
        Debug.Log("Ground Pound w/ " + start.ToString() + " and " + end.ToString());

        //Linecast, looking for items on the layer "Fighting"
        RaycastHit2D[] linecastResult = Physics2D.LinecastAll(start, end, 1 << LayerMask.NameToLayer("Fighting"));

        //Create a line so that it is possible to see where the raycasts are going.
        Debug.DrawLine(start, end, Color.green, 3f);

        //Go through all linecast results and look for the health panel.
        if (linecastResult.Length != 0)
        {
            for (int i = 0; i < linecastResult.Length; i++)
            {
                //Check to make sure that the collider has a second parent.
                //If the collider has a parent and not a second parent, short-circuiting prevents an error.
                if (linecastResult[i].collider.transform.parent != null && linecastResult[i].collider.transform.parent.parent != null)
                {
                    Transform healthPanelTransform = linecastResult[i].collider.transform.parent.parent;
                    //Make sure that the character has a health panel manager and that the character is not attacking itself.
                    if (healthPanelTransform.GetComponent <T> () != null)
                    {
                        //Return the health panel manager if it exists.
                        return(healthPanelTransform.GetComponent <T> ());
                    }
                }
            }
        }

        //In the event that none of the results had a health panel manager.
        return(default(T));
    }
Exemplo n.º 24
0
    public void LinecastCut(Vector2 lineStart, Vector2 lineEnd, int layerMask = Physics2D.AllLayers)
    {
        Stick             stick            = FindObjectOfType <Stick>();
        List <GameObject> gameObjectsToCut = new List <GameObject>();

        RaycastHit2D[] hits = Physics2D.LinecastAll(lineStart, lineEnd, layerMask);
        foreach (RaycastHit2D hit in hits)
        {
            if (HitCounts(hit))
            {
                gameObjectsToCut.Add(hit.transform.gameObject);
            }
        }

        foreach (GameObject go in gameObjectsToCut)
        {
            SpriteCutterOutput output = SpriteCutter.Cut(new SpriteCutterInput()
            {
                lineStart              = lineStart,
                lineEnd                = lineEnd,
                gameObject             = go,
                gameObjectCreationMode = SpriteCutterInput.GameObjectCreationMode.CUT_OFF_ONE,
            });

            if (output != null && output.secondSideGameObject != null)
            {
                //Rigidbody2D newRigidbody = output.secondSideGameObject.AddComponent<Rigidbody2D>();
                //newRigidbody.velocity = output.firstSideGameObject.GetComponent<Rigidbody2D>().velocity;
                output.secondSideGameObject.transform.position = stick.transform.position;
                SlicedStick slicedStick = output.secondSideGameObject.AddComponent <SlicedStick>();;
            }
        }
    }
Exemplo n.º 25
0
        private RaycastHit2D[] GetLineCastAll()
        {
            var fromPos = fromPosition.Value;

            var fromGo = Fsm.GetOwnerDefaultTarget(fromGameObject);

            if (fromGo != null)
            {
                fromPos.x += fromGo.transform.position.x;
                fromPos.y += fromGo.transform.position.y;
            }

            var toPos = toPosition.Value;

            var toGo = toGameObject.Value;

            if (toGo != null)
            {
                toPos.x += toGo.transform.position.x;
                toPos.y += toGo.transform.position.y;
            }


            if (minDepth.IsNone && maxDepth.IsNone)
            {
                return(Physics2D.LinecastAll(fromPos, toPos, ActionHelpers.LayerArrayToLayerMask(layerMask, invertMask.Value)));
            }
            else
            {
                var _minDepth = minDepth.IsNone? Mathf.NegativeInfinity : minDepth.Value;
                var _maxDepth = maxDepth.IsNone? Mathf.Infinity : maxDepth.Value;
                return(Physics2D.LinecastAll(fromPos, toPos, ActionHelpers.LayerArrayToLayerMask(layerMask, invertMask.Value), _minDepth, _maxDepth));
            }
        }
Exemplo n.º 26
0
    void Update()
    {
        Vector2 currentPosition = new Vector2(transform.position.x, transform.position.y);
        Vector2 newPosition     = currentPosition + velocity * Time.deltaTime;

        Debug.DrawLine(currentPosition, newPosition, Color.red);
        RaycastHit2D[] hits = Physics2D.LinecastAll(currentPosition, newPosition);
        transform.position = newPosition;
        foreach (RaycastHit2D hit in hits)
        {
            GameObject other = hit.collider.gameObject;
            if (other != archer)
            {
                if (other.CompareTag("Wall"))
                {
                    Debug.Log("Arrow hit wall");
                    this.enabled = false;
                    break;
                }
                if (other.CompareTag("Door"))
                {
                    Debug.Log("Arrow hit door");
                    Destroy(gameObject);
                    break;
                }
                if (other.CompareTag("Player"))
                {
                    Debug.Log("Arrow hit player");
                    Destroy(gameObject);
                    break;
                }
            }
        }
    }
Exemplo n.º 27
0
    void Update()
    {
        Vector2 currentPosition = new Vector2(transform.position.x, transform.position.y);
        Vector2 newPosition     = currentPosition + velocity * Time.deltaTime;


        Debug.DrawLine(currentPosition + offset, newPosition + offset, Color.red);

        RaycastHit2D[] hits = Physics2D.LinecastAll(currentPosition + offset, newPosition + offset);

        foreach (RaycastHit2D hit in hits)
        {
            GameObject other = hit.collider.gameObject;
            if (other != self)
            {
                if (other.CompareTag("Players"))
                {
                    Destroy(gameObject);
                    Debug.Log(other.name);
                    break;
                }

                if (other.CompareTag("Walls"))
                {
                    Destroy(gameObject);
                    break;
                }
            }
        }


        transform.position = newPosition;
    }
Exemplo n.º 28
0
    public void MovePlatformBlockersFromRotation(float diff, Vector2 center)
    {
        Dictionary <IPlatformMoveBlocker, Vector3> moves = new Dictionary <IPlatformMoveBlocker, Vector3>();

        foreach (var pt in GeneratePoints().All)
        {
            var            end   = pt;
            var            start = end.RotateAround(-diff, center);
            RaycastHit2D[] hits  = Physics2D.LinecastAll(start, end, passengerMask);
            foreach (var h in hits)
            {
                var blocker = h.collider.GetComponent <IPlatformMoveBlocker>();
                var amt     = end - h.point;
                if (moves.ContainsKey(blocker))
                {
                    var move = moves[blocker];
                    if (amt.sqrMagnitude > move.sqrMagnitude)
                    {
                        move = amt;
                    }
                }
                else
                {
                    moves.Add(blocker, amt);
                }
            }
        }

        foreach (var m in moves)
        {
            m.Key.MoveFromRotation(m.Value);
        }
    }
Exemplo n.º 29
0
    private void Update()
    {
        Vector2 currentPos = gameObject.transform.position;
        Vector2 newPos     = currentPos + _velocity * _speed * Time.deltaTime;

        Debug.DrawLine(currentPos, newPos, Color.red);
        RaycastHit2D[] hits = Physics2D.LinecastAll(currentPos, newPos);


        foreach (var hit in hits)
        {
            GameObject other = hit.collider.gameObject;
            if (other != Player)
            {
                if (other.CompareTag("Wall"))
                {
                    Destroy(gameObject);
                    break;
                }
                if (other.CompareTag("Player") && _projetileOwner != ProjectileOwner.PLAYER)
                {
                    //Aply Damage
                    other.GetComponent <PlayerHPControl>().recieveDamage(Damage, gameObject);
                    Destroy(gameObject);
                    break;
                }
            }
        }

        transform.position = newPos;
    }
Exemplo n.º 30
0
        /// <summary>
        /// Get door rays between two other view rays
        /// </summary>
        /// <param name="door"></param>
        /// <param name="viewPoint"></param>
        /// <param name="viewHits"></param>
        /// <param name="ray1"></param>
        /// <param name="ray2"></param>
        /// <param name="viewRayDir1"></param>
        /// <param name="viewRayDir2"></param>
        void GetDoorRays(Door door, Vector2 viewPoint, Vector2[] viewHits, out RayInfo ray1, out RayInfo ray2, Vector2 viewRayDir1, Vector2 viewRayDir2, Dictionary <Vector2, Color> debugHit)
        {
            ray1.origin    = door.point1;
            ray1.direction = (door.point1 - viewPoint).normalized;
            ray2.origin    = door.point2;
            ray2.direction = (door.point2 - viewPoint).normalized;

            bool horizontal = ApproximatelyEqual(door.point1.y, door.point2.y);
            bool pDouble    = false;

            RaycastHit2D[] hits = Physics2D.LinecastAll(viewPoint, door.point1 - ray1.direction * 0.001f, ViewLayerMask);
            if (hits.Length > 1 || !AngleIsBetween(viewRayDir1, viewRayDir2, ray1.direction))              // If we can't see this doorjamb
            {
                pDouble = true;
                ray1    = GetHitOnDoor(door, viewHits, viewPoint, horizontal /*, debugHit*/);
            }

            hits = Physics2D.LinecastAll(viewPoint, door.point2 - ray2.direction * 0.001f, ViewLayerMask);
            if (hits.Length > 1 || !AngleIsBetween(viewRayDir1, viewRayDir2, ray2.direction))             // If we can't see this doorjamb
            {
                ray2 = GetHitOnDoor(door, viewHits, viewPoint, horizontal /*, debugHit*/);
                if (pDouble)
                {
                    //Double non visible jambs
                }
            }
            else
            {
                //print(hits.Length);
            }

            /*debugHit.Addd(ray1.origin, Color.blue);
            *  debugHit.Addd(ray2.origin, Color.cyan);*/
        }