예제 #1
0
    Fix64Vector2 FindClosestVector2()
    {
        GameObject[] Allthem  = GameObject.FindGameObjectsWithTag("Player");
        Fix64        sqrdis   = Fix64.MaxValue;
        Fix64Vector2 position = (Fix64Vector2)GetComponent <Rigidbody2D>().position;
        Fix64Vector2 vector   = (Fix64Vector2)GetComponent <Rigidbody2D>().velocity;

        foreach (GameObject Him in Allthem)
        {
            //Debug.Log(Him.name);
            if (Him == sender)
            {
                continue;               //跳过施法者
            }
            Fix64Vector2 diff        = ((Fix64Vector2)Him.GetComponent <Rigidbody2D>().position - position);
            Fix64        curDistance = diff.LengthSquare(); //向量距离平方
            if (curDistance <= sqrdis)
            {
                sqrdis = curDistance; //更新最近距离
                vector = diff;        //更新向量
            }
            //Debug.Log(vector.LengthSquare());
        }
        Fix64Vector2 v2r = (vector.normalized() * speed);

        return(v2r);
    }
예제 #2
0
    void FixedUpdate()
    {
        if (Target == null)
        {
            return;
        }
        Fix64Vector2 direction = (Fix64Vector2)Target.position - (Fix64Vector2)selfrb2d.position;

        if (direction.LengthSquare() <= (Fix64)0.3)
        {
            gethome();
        }
        selfrb2d.velocity = (direction.normalized() * (Fix64)Speed).ToV2();
    }
예제 #3
0
파일: SkillE1.cs 프로젝트: xz000/testingLL
    public void Skill(Fix64Vector2 actionplace)
    {
        Fix64Vector2 singplace      = (Fix64Vector2)GetComponent <Rigidbody2D>().position;
        Fix64Vector2 skilldirection = actionplace - singplace;

        GetComponent <DoSkill>().BeforeSkill();
        Fix64 mdf = (Fix64)maxdistance;

        if (skilldirection.LengthSquare() > mdf * mdf)
        {
            actionplace = singplace + skilldirection.normalized() * mdf;
        }
        GameObject MyRock = Instantiate(TheRock, actionplace.ToV2(), Quaternion.identity);

        MyRock.GetComponent <RockExplode>().damage    = damage;
        MyRock.GetComponent <RockExplode>().bombforce = bombforce;
        currentcooldown = 0;
        skillavaliable  = false;
    }
예제 #4
0
    public void Skill()
    {
        //photonView.RPC("RealSkill", PhotonTargets.All);
        //gameObject.GetComponent<MoveScript>().stopwalking();
        //gameObject.GetComponent<StealthScript>().StealthEnd();
        currentcooldown = 0;
        skillavaliable  = false;
        float        radius      = 2;
        Vector2      actionplace = transform.position;
        Fix64        rfix        = (Fix64)4;
        Fix64Vector2 apf         = new Fix64Vector2(actionplace);

        Collider2D[] colliders = Physics2D.OverlapCircleAll(actionplace, radius);
        foreach (Collider2D hit in colliders)
        {
            HPScript hp = hit.GetComponent <HPScript>();
            if (hp != null)
            {
                if (hit == gameObject.GetComponent <Collider2D>())
                {
                    hp.GetHurt(Mathf.Min(10, hp.currentHP - 1));
                }
                else
                {
                    Rigidbody2D  rb        = hit.GetComponent <Rigidbody2D>();
                    Fix64Vector2 rbpf      = new Fix64Vector2(rb.position);
                    Fix64Vector2 explforce = rbpf - apf;
                    if (explforce.LengthSquare() > rfix)
                    {
                        continue;
                    }
                    hp.GetHurt(10);
                    hit.GetComponent <RBScript>().GetPushed(explforce.normalized() * (Fix64)9, 1f);
                }
            }
        }
    }
예제 #5
0
    GameObject FindClosestEnemy()
    {
        GameObject closest = null;  // GameObject.FindWithTag("Player");

        GameObject[] Allthem  = GameObject.FindGameObjectsWithTag("Player");
        Fix64        sqrdis   = Fix64.MaxValue;
        Fix64Vector2 position = (Fix64Vector2)GetComponent <Rigidbody2D>().position;

        foreach (GameObject Him in Allthem)
        {
            if (Him == sender)
            {
                continue;                                                                                    //跳过施法者
            }
            Fix64Vector2 diff        = ((Fix64Vector2)Him.GetComponent <Rigidbody2D>().position - position); //距离向量
            Fix64        curDistance = diff.LengthSquare();                                                  //距离平方
            if (curDistance < sqrdis)
            {
                closest = Him;         //更新最近距离敌人
                sqrdis  = curDistance; //更新最近距离
            }
        }
        return(closest);
    }