Beispiel #1
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (!photonView.IsMine && !forceMovement)
        {
            return;
        }
        //this is a shit way to do checkpoints but we don't really have the time at this point
        if (other.gameObject.layer == 13)
        {
            if (activeCheckpoint.y < other.ClosestPoint(transform.position).y)
            {
                activeCheckpoint = other.ClosestPoint(transform.position);
            }
        }

        if (other.gameObject.layer == 14)
        {
            Debug.Log("finish flaggggg");
            ExitGames.Client.Photon.Hashtable initialProps = new ExitGames.Client.Photon.Hashtable()
            {
                { "finished", true }
            };
            PhotonNetwork.LocalPlayer.SetCustomProperties(initialProps);
            //Debug.Log(CheckFinished())
            if (!hasFinishedLevel && CheckFinished())
            {
                LoadNextLevel();
            }
        }

        if (other.gameObject.layer == 10)
        {
            onRope = true;
        }
    }
Beispiel #2
0
        private Vector2 GetRandomPointWithinSpawnerPerlinNoise()
        {
            var threshold = .5f;

            for (int i = 0; i < MAX_ITERATIONS * 2; i++)
            {
                var point = new Vector2(
                    Random.Range(boundaries.bounds.min.x, boundaries.bounds.max.x),
                    Random.Range(boundaries.bounds.min.y, boundaries.bounds.max.y)
                    );
                var perlinNoise = Mathf.PerlinNoise(
                    perlinVar.x + (point.x - worldSpaceOffset.x) / (scale * boundaries.bounds.size.x),
                    perlinVar.y + (point.y - worldSpaceOffset.y) / (scale * boundaries.bounds.size.y));
                if (perlinNoise < threshold)
                {
                    continue;
                }
                if (point == boundaries.ClosestPoint(point))
                {
                    return(point);
                }
            }

            Debug.LogError("Bad Luck at finding point inside a collider and perlin noise!");
            return(new Vector2());
        }
Beispiel #3
0
    private IEnumerator plantCo(Collider2D plataform)
    {
        yield return(new WaitForSeconds(delayTime));

        if (plantDirection(Vector2.down))
        {
            GameObject clone = Instantiate(plant, plataform.ClosestPoint(plantPosition.position), Quaternion.Euler(new Vector3(0, 0, 0)));
            clone.GetComponent <PlantGrow>().isSideway      = false;
            clone.GetComponent <PlantGrow>().sideCorrection = 1;
            Destroy(gameObject);
        }
        else if (plantDirection(Vector2.left))
        {
            GameObject clone = Instantiate(plant, plataform.ClosestPoint(plantPosition.position), Quaternion.Euler(new Vector3(0, 0, -90)));
            clone.GetComponent <PlantGrow>().isSideway      = true;
            clone.GetComponent <PlantGrow>().sideCorrection = -1;
            Destroy(gameObject);
        }
        else if (plantDirection(Vector2.right))
        {
            GameObject clone = Instantiate(plant, plataform.ClosestPoint(plantPosition.position), Quaternion.Euler(new Vector3(0, 0, 90)));
            clone.GetComponent <PlantGrow>().isSideway      = true;
            clone.GetComponent <PlantGrow>().sideCorrection = 1;
            Destroy(gameObject);
        }
        else if (myRigidbody.bodyType != RigidbodyType2D.Static)
        {
            myRigidbody.velocity = Vector2.zero;
        }
    }
Beispiel #4
0
    protected bool canStandUp()
    {
        UnityEngine.Object[] os  = FindObjectsOfType(typeof(GameObject));
        float   midX             = this.gameObject.transform.position.x;
        float   offset           = this.gameObject.GetComponent <Collider2D>().bounds.size.x / 2f;
        float   topYOnMaxScale   = this.gameObject.transform.position.y + this.gameObject.GetComponent <Collider2D>().bounds.size.y;
        Vector2 pointToTestLeft  = new Vector2(midX - offset, topYOnMaxScale);
        Vector2 pointToTestRight = new Vector2(midX + offset, topYOnMaxScale);

        foreach (UnityEngine.Object o in os)
        {
            GameObject go = (GameObject)o;
            if (go.layer == PlayerMovement.layerDuckObstacles)
            {
                Collider2D coll        = go.GetComponent <Collider2D>();
                Vector2    closestLeft = coll.ClosestPoint(pointToTestLeft);
                if (closestLeft == pointToTestLeft)
                {
                    return(false);
                }
                Vector2 closestRight = coll.ClosestPoint(pointToTestRight);
                if (closestRight == pointToTestRight)
                {
                    return(false);
                }
            }
        }
        return(true);
    }
Beispiel #5
0
    void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.tag == "SubWeapon")
        {
            HitEffect(collision.ClosestPoint(transform.position));
            collision.gameObject.GetComponent <SubWeapon>().Damage(Damage);
            IsDisappear = false;

            gameObject.SetActive(false);
        }
        else if (collision.gameObject.tag == "Player")
        {
            HitEffect(collision.ClosestPoint(transform.position));
            collision.gameObject.GetComponent <Player>().Damage(Damage);
            IsDisappear = false;

            gameObject.SetActive(false);
        }
        else if (collision.gameObject.tag == "Border")
        {
            if (IsDisappear)
            {
                IsDisappear = false;
                gameObject.SetActive(false);
            }
        }
    }
    //xu ly va cham trigger giua projectTile với player va enemy
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.CompareTag("Enemy"))
        {
            Release();
            EnemyController enemy;
            //tim enemy controller script
            collision.gameObject.TryGetComponent(out enemy);
            enemy.hit(damage);
            Vector3 hitpos = collision.ClosestPoint(transform.position);
            SpawnManager.Instance.spawnHitFX(hitpos);
        }
        if (collision.gameObject.CompareTag("Player"))
        {
            Release();
            PlayerController player;
            //tim player controller script
            collision.gameObject.TryGetComponent(out player);

            if (player.haveShield)
            {
                // have Shield
                player.shield.SetActive(true);
                player.haveShield = true;
                return;
            }
            else
            {
                // haven't Shield
                player.hit(damage);
                Vector3 hitpos = collision.ClosestPoint(transform.position);
                SpawnManager.Instance.spawnHitFX(hitpos);
            }
        }
    }
    void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.tag == "BlockBullet" ||
            collision.gameObject.tag == "PierceBullet" ||
            collision.gameObject.tag == "Chain")
        {
            Vector2 hitPos = collision.ClosestPoint(gameObject.transform.position);
            HitEffect(hitPos);

            collision.gameObject.SetActive(false);
        }
        else if (collision.gameObject.tag == "SubWeapon")
        {
            Vector2 hitPos = collision.ClosestPoint(gameObject.transform.position);
            HitEffect(hitPos);
            collision.gameObject.GetComponent <SubWeapon>().Damage(Damage);

            gameObject.SetActive(false);
        }
        else if (collision.gameObject.tag == "Player")
        {
            Vector2 hitPos = collision.ClosestPoint(gameObject.transform.position);
            HitEffect(hitPos);
            collision.gameObject.GetComponent <Player>().Damage(Damage);

            gameObject.SetActive(false);
        }
    }
 private void OnTriggerEnter2D(Collider2D collider)
 {
     if (collider.tag == "Character")
     {
         CharacterContact(collider.GetComponent <Character>(), collider.ClosestPoint(transform.position));
     }
     else if (collider.tag == "Ground")
     {
         GroundContact(collider.ClosestPoint(transform.position));
     }
 }
Beispiel #9
0
 //Look into SLERPing for this
 void OnTriggerStay2D(Collider2D col)
 {
     if (col.ClosestPoint(transform.position).x >= transform.localPosition.x || col.ClosestPoint(transform.position).y >= transform.localPosition.y)
     {
         parent.transform.rotation = Quaternion.Euler(0f, 0f, parent.transform.rotation.eulerAngles.z + (turnRate * 3));
         Debug.Log(col.gameObject.name);
     }
     else
     {
         parent.transform.rotation = Quaternion.Euler(0f, 0f, parent.transform.rotation.eulerAngles.z + (-turnRate * 3));
     }
 }
 void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.gameObject.tag == "SubWeapon")
     {
         HitEffect(collision.ClosestPoint(transform.position));
         collision.gameObject.GetComponent <SubWeapon>().Damage(Damage);
     }
     else if (collision.gameObject.tag == "Player")
     {
         HitEffect(collision.ClosestPoint(transform.position));
         collision.gameObject.GetComponent <Player>().Damage(Damage);
     }
 }
    void OnTriggerEnter2D(Collider2D other)
    {
        //Debug.Log(other.tag);
        if (other.tag == "Wall")
        {
            Vector2 position     = transform.position;
            var     wallPosition = other.ClosestPoint(position);

            /*
             * //if (!Mathf.Approximately(wallPosition.y, position.y) && !Mathf.Approximately(wallPosition.x, position.x))
             * Debug.Log("Position Y: " + position.y + ", Position Wall Y: "  + wallPosition.y + ", Position X: " + position.x + ", Position Wall X: " + wallPosition.x);
             * Debug.Log("Position Y: " + System.Math.Round(position.y, 2) + ", Position Wall Y: " + System.Math.Round(wallPosition.y, 2) + ", Position X: " + System.Math.Round(wallPosition.x, 2) + ", Position Wall X: " + System.Math.Round(position.x, 2));
             */
            if (System.Math.Round(wallPosition.y, 3) != System.Math.Round(position.y, 3))
            {
                directionY = 0 - directionY;
            }

            if (System.Math.Round(wallPosition.x, 3) != System.Math.Round(position.x, 3))
            {
                directionX = 0 - directionX;
            }

            ChangeRotation();
        }
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (!photonView.IsMine)
        {
            return;
        }

        //Debug.Log("Trigger: " + collision.tag);
        //Debug.Log("Ball Collided: " + collision.ClosestPoint(this.gameObject.transform.position));
        PhotonView target = collision.gameObject.GetComponent <PhotonView>();

        if (target == null)
        {
            this.GetComponent <PhotonView>().RPC("Bounce", RpcTarget.AllBuffered, collision.ClosestPoint(this.gameObject.transform.position));
            //ParentObject.GetComponent<SluggerController>().UpdateSpecialMeter(Damage);
        }
        else if (target != null && (!target.IsMine || target.IsSceneView))
        {
            if (collision.tag == "Player")
            {
                target.RPC("ReduceHealth", RpcTarget.AllBuffered, Damage);
                ParentObject.GetComponent <SluggerController>().UpdateSpecialMeter(Damage);

                if (target.GetComponent <PlayerHealth>().CurrentHealth <= 0)
                {
                    ParentObject.GetComponent <PlayerHealth>().YouEliminated("");
                }
            }
            this.GetComponent <PhotonView>().RPC("DestroyOBJ", RpcTarget.AllBuffered);
        }
    }
Beispiel #13
0
    private IEnumerator moveCloser(Collider2D collision)
    {
        yield return(null);

        transform.position += (Vector3)(collision.ClosestPoint(transform.position) -
                                        gameObject.GetComponent <Collider2D>().ClosestPoint(collision.transform.position));
    }
Beispiel #14
0
    IEnumerator ReflectShot(Collider2D collision)
    {
        var comp  = collision.GetComponent <ProjectileController>();
        var speed = comp.projectileSpeed;

        comp.projectileSpeed = 0f;
        var hit         = collision.ClosestPoint(collision.gameObject.transform.position);
        var playerPos   = player.transform.position;
        var oldPlayerUp = player.transform.up;

        if (collision)
        {
            var normalVector = hit - (Vector2)(playerPos - oldPlayerUp / 3.5f);
            debugNormal            = normalVector;
            debugPoint             = hit;
            collision.transform.up = Vector2.Reflect(collision.transform.up, normalVector.normalized);
            AudioController.instance.PlayShieldSound();
        }

        yield return(new WaitForSeconds(0.2f));


        if (collision)
        {
            float deltaAngle = Vector2.SignedAngle(oldPlayerUp, player.transform.up) * AngleDamping;
            collision.transform.Rotate(0, 0, Mathf.Clamp(deltaAngle, -90, 90));
            comp.projectileSpeed = speed;
        }

        yield break;
    }
Beispiel #15
0
    //calculating the random point
    Vector2 GetRandomPointInCollider()
    {
        Vector2 point = new Vector2(
            Random.Range(outsideCollider.bounds.min.x, outsideCollider.bounds.max.x),
            Random.Range(outsideCollider.bounds.min.y, outsideCollider.bounds.max.y)
            );

        //if the point is outside of the outside collider, get a new one
        if (point != outsideCollider.ClosestPoint(point))
        {
            Debug.Log("Out of the collider! Looking for the other point...");
            point = GetRandomPointInCollider();  //cycles through again to see if the point exists
        }

        //if the point is inside of the inner collider, get a new one
        if (IsPointWithinCollider(insideCollider, point))
        {
            point = GetRandomPointInCollider();
        }

        //if the point isnt far away, select a new one
        if (Vector2.Distance(this.transform.position, point) < 5)
        {
            point = GetRandomPointInCollider();
        }

        return(point);
    }
Beispiel #16
0
    void OnTriggerEnter2D(Collider2D col)
    {
        Debug.Log(col.gameObject.name);
        int x = (int)player.transform.position.x;
        int y = (int)player.transform.position.y;

        for (int i = -1; i < 1; i++)
        {
            for (int j = -1; j < 1; j++)
            {
                FindObjectOfType <MapManager_V2>().DestroyTile((x + i, y + j));
            }
        }

        if (col.tag == "Walls")
        {
            Vector2 point = col.ClosestPoint(transform.position);
            Debug.Log("wall hit + " + point);
        }

        Health health = col.GetComponent <Health>();

        if (health != null)
        {
            health.TakeDamage(damage);
        }
    }
Beispiel #17
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        ChangeState(State.Idle);
        var dir = collision.ClosestPoint(transform.position);

        transform.Translate(dir.normalized * .01f);
    }
Beispiel #18
0
    private bool isOnScreen(Vector2 point)
    {
        Vector2 closest = screenTrigger.ClosestPoint(point);

        // Fun fact from answers.unity.com: If the given point is inside the collider, ClosestPoint will return that point
        return(closest == point);
    }
Beispiel #19
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        foreach (GameObject go in collisions)
        {
            if (go == collision.gameObject)
            {
                return;
            }
        }

        collisions.Add(collision.gameObject);

        pointPFX = collision.ClosestPoint(headPoint.position);

        if (collision.gameObject.IsOnLayerMask(hitableMask))
        {
            collision.attachedRigidbody.AddForce(club.ActiveSwingForce * club.ActiveSwingDirection, ForceMode2D.Impulse);

            collision.gameObject.GetComponent <GolfBall>().PlaySwingHit(pointPFX);
        }
        else
        {
            collision.gameObject.GetComponent <Obstacle>().PlaySwingHit(pointPFX);
        }
    }
Beispiel #20
0
    private Vector2 GetClosestColliderPointFromLine(RaycastHit2D ropeHit, Collider2D collider)
    {
        //var closestVector = collider.ClosestPoint(ropePointHit);
        var closestVectorTell = collider.ClosestPoint(ropeHit.point);

        return(closestVectorTell);
    }
Beispiel #21
0
    List <Vector2> getClosestPoints(Collider2D col, List <string> avoidTags)
    {
        Collider2D[] hitColliders = new Collider2D[20];
        Physics2D.OverlapCollider(col, new ContactFilter2D(), hitColliders);

        //Collider2D[] hitColliders = Physics2D.OverlapCircleAll(transform.position, separation_radius);

        //List<Collider2D> avoidColliders = new List<Collider2D>();
        //current_colliders = avoidColliders;
        List <Vector2> closest = new List <Vector2>();

        //list of my colliders


        //creates new list of colliders that contain avoid tags
        for (int i = 0; i < hitColliders.Length; i++)
        {
            if (hitColliders[i] == null)
            {
                break;
            }

            if (avoidTags.Contains(hitColliders[i].tag) && !myColliders.Contains(hitColliders[i]))
            {
                Collider2D currentCol = hitColliders[i];
                //avoidColliders.Add(currentCol);
                closest.Add(currentCol.ClosestPoint(transform.position + transform.up * 0.15f));
            }
        }
        closestColliderPoints = closest;


        return(closest);
    }
Beispiel #22
0
    public static bool IsPointWithinCollider(Collider2D collider, Vector3 point)
    {
        Vector3 closest = collider.ClosestPoint(point);

        // Because closest=point if point is inside - not clear from docs I feel
        return(closest == point);
    }
    // Start is called before the first frame update
    void Start()
    {
        // Explode
        Vector2 thisPos = transform.position;

        Collider2D[] hits = Physics2D.OverlapCircleAll(thisPos, damageRadius, damageMask);
        for (int i = 0; i < hits.Length; i++)
        {
            // Calculate fallout damage
            Collider2D hit = hits[i];
            float      distFromEpicenter = Vector2.Distance(thisPos, hit.ClosestPoint(thisPos));
            float      damageDealt       = Mathf.Clamp(1.0f - (distFromEpicenter / damageRadius), 0.0f, 1.0f) * damage;

            // subtract victim health
            Health victimHealth = hit.GetComponent <Health>();
            victimHealth.damage(damageDealt);
        }

        // misc
        timeToDestroy      = Time.time + oscillateDuration;
        oscillateInterval  = oscillateDuration / numOscillation;
        timeToBounce       = Time.time + oscillateInterval;
        currForce          = initialForce;
        forceField.gravity = currForce;
    }
Beispiel #24
0
        protected virtual void Update()
        {
            if (!_isOpen)
            {
                return;
            }
            if (!_skippedFrame)
            {
                _skippedFrame = true; return;
            }

            if (!Inventory.ContainerOpen || Inventory.currentContainer != this)
            {
                _isOpen = false;
            }
            else if (Input.GetKeyUp(KeyCode.E) || Input.GetKeyUp(KeyCode.Escape))
            {
                Inventory.OpenCloseContainer(this, gameObject.name);
                _isOpen = false;
            }
            else
            {
                Collider2D col = GetComponent <Collider2D>();

                float distanceFromPlayer = (Player.position - col.ClosestPoint(Player.position)).sqrMagnitude;
                if (distanceFromPlayer <= 0.5f)
                {
                    return;
                }

                Inventory.OpenCloseContainer(this, gameObject.name);
                _isOpen = false;
            }
        }
Beispiel #25
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (false == enable)
        {
            return;
        }

        var body = collision.transform.GetComponentInChildren <Chara>();

        if (body == null)
        {
            return;
        }

        if (false == LocalPlayer.Instance.IsEnemy(body))
        {
            return;
        }

        var hitRadius = (collision.transform.position - transform.position).magnitude;

        // 現実はhitRadiusの2乗な気がする
        var damageFactor   = attackPower * hitRadius * (Mathf.Abs(rotVel) / rotVelMax);
        var knockbackPower = knockbackPowerRate * hitRadius;

        var hitPosition = collision.ClosestPoint(transform.position);

        SoundManager.Instance.Play(hitSE);

        EffectMan.Instance.PlayOneEffect(hitEffect, hitPosition, Quaternion.identity);

        LocalPlayer.Instance.SendDamage(
            body,
            new AttackInfo(LocalPlayer.Instance, damageFactor, hitPosition, knockbackPower));
    }
Beispiel #26
0
    public float DistanceTo(ShipStructure structure)
    {
        Vector2 closestShipPoint      = structure.ClosestPoint(transform.position);
        Vector2 closestComponentPoint = collider2d.ClosestPoint(closestShipPoint);

        return(Vector2.Distance(closestShipPoint, closestComponentPoint));
    }
    // Update is called once per frame
    void Update()
    {
        Vector2 mostBottomLeftPoint = collider.ClosestPoint(new Vector2(-1000, -1000));
        int     newSortingOrder     = -(int)(mostBottomLeftPoint.y * SortingOrderPerYUnit);

        renderer.sortingOrder = newSortingOrder;
    }
 void OnTriggerEnter2D(Collider2D col)
 {
     if (col.gameObject.tag == "Ladder")
     {
         inLadder = true;
         // TODO: hardcodd the small difference between entering ladder from left vs right
         ladderTileXPosition = col.ClosestPoint(this.transform.position).x;
         ladderTileXPosition = Mathf.Round(ladderTileXPosition * 4) / 4;
     }
     if (col.gameObject.tag == "LadderTop")
     {
         inLadderTop         = true;
         ladderTileXPosition = col.ClosestPoint(this.transform.position).x;
         ladderTileXPosition = Mathf.Round(ladderTileXPosition * 4) / 4;
     }
 }
Beispiel #29
0
 // land on collision
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (!canJump)
     {
         Land(collision.gameObject.transform, collision.ClosestPoint(transform.position));
     }
 }
Beispiel #30
0
    Vector2 GetRandomPointInsideSpawnArea()
    {
        float _x = Random.Range(spawnArea.bounds.min.x, spawnArea.bounds.max.x);
        float _y = Random.Range(spawnArea.bounds.min.y, spawnArea.bounds.max.y);

        return(spawnArea.ClosestPoint(new Vector2(_x, _y)));
    }