Пример #1
0
    void ApplyPhysics(Vector3 wDir, Collider col, Vector3 vel)
    {
        GameObject go   = col.gameObject;
        Rigidbody  body = go.rigidbody;

        //Vector3 up = go.transform.up;

        if (((1 << go.layer) & layerMask) != 0 && CheckTags(go) && (!upDirLimitEnabled || Vector3.Angle(wDir, col.transform.up) <= upDirLimit)) // && Vector3.Angle(up, hit.normal) >= normalAngleDiff) {
        //Vector3 vel = rigidbody.GetPointVelocity(hit.point);

        {
            PlatformerController ctrl = go.GetComponent <PlatformerController>();

            bool jumping = ctrl != null && (ctrl.isJump || ctrl.isJumpWall);

            Vector3 localV  = go.transform.worldToLocalMatrix.MultiplyVector(vel);
            Vector3 nLocalV = jumping && jumpBoost ? new Vector3(0, localV.y > 0 ? localV.y : 0) : new Vector3(localV.x, localV.y < 0 ? localV.y : 0);
            Vector3 nWorldV = go.transform.localToWorldMatrix.MultiplyVector(nLocalV);

            if (jumping)
            {
                if (jumpBoost)
                {
                    if (!mPlatformers.Contains(ctrl))
                    {
                        body.velocity += nWorldV;
                    }
                }
                else if (localV.y > 0.0f)
                {
                    body.MovePosition(body.position + nWorldV * Time.fixedDeltaTime);
                }
            }
            else
            {
                body.MovePosition(body.position + nWorldV * Time.fixedDeltaTime);
            }

            //body.velocity += go.transform.localToWorldMatrix.MultiplyVector(nLocalV);

            /*if(velocityAngleDiff == 0 || body.velocity == Vector3.zero || Vector3.Angle(wDir, vel) >= velocityAngleDiff) {
             *          body.MovePosition(go.transform.position + vel * Time.fixedDeltaTime);
             *          //body.velocity += vel;
             *      }*/

            if (ctrl && !jumping)
            {
                mPlatformerSweep.Add(ctrl);
                ctrl._PlatformSweep(true, gameObject.layer);
            }
        }
    }
Пример #2
0
    // Update is called once per frame
    void FixedUpdate()
    {
#if UNITY_EDITOR
        SetDir();
#endif
        Vector3 vel = rigidbody.velocity;// GetPointVelocity(hit.point);

        if (vel != Vector3.zero)
        {
            Vector3 wDir = transform.rotation * mDir;

            RaycastHit[] hits = rigidbody.SweepTestAll(wDir, ofs);

            foreach (RaycastHit hit in hits)
            {
                GameObject go   = hit.collider.gameObject;
                Rigidbody  body = go.rigidbody;
                //Vector3 up = go.transform.up;

                if (((1 << go.layer) & layerMask) != 0 && CheckTags(go) && (!upDirLimitEnabled || Vector3.Angle(wDir, hit.transform.up) <= upDirLimit)) // && Vector3.Angle(up, hit.normal) >= normalAngleDiff) {

                {
                    PlatformerController ctrl = go.GetComponent <PlatformerController>();

                    bool jumping = ctrl != null && (ctrl.isJump || ctrl.isJumpWall);

                    Vector3 localV  = go.transform.worldToLocalMatrix.MultiplyVector(vel);
                    Vector3 nLocalV = jumping ? new Vector3(0, localV.y > 0 ? localV.y : 0) : new Vector3(localV.x, localV.y < 0 ? localV.y : 0);
                    Vector3 nWorldV = go.transform.localToWorldMatrix.MultiplyVector(nLocalV);

                    if (jumping)
                    {
                        if (!mPlatformers.Contains(ctrl))
                        {
                            body.velocity += nWorldV;
                        }
                    }
                    else
                    {
                        body.MovePosition(body.position + nWorldV * Time.fixedDeltaTime);
                    }

                    //body.velocity += go.transform.localToWorldMatrix.MultiplyVector(nLocalV);

                    /*if(velocityAngleDiff == 0 || body.velocity == Vector3.zero || Vector3.Angle(wDir, vel) >= velocityAngleDiff) {
                     *  body.MovePosition(go.transform.position + vel * Time.fixedDeltaTime);
                     *  //body.velocity += vel;
                     * }*/

                    if (ctrl && !jumping)
                    {
                        mCurPlatformerSweep.Add(ctrl);
                        ctrl._PlatformSweep(true, gameObject.layer);
                    }
                }
            }
        }

        foreach (PlatformerController ctrl in mPlatformers)
        {
            if (!mCurPlatformerSweep.Contains(ctrl))
            {
                ctrl._PlatformSweep(false, gameObject.layer);
            }
        }

        HashSet <PlatformerController> prev = mPlatformers;
        mPlatformers        = mCurPlatformerSweep;
        mCurPlatformerSweep = prev;
        mCurPlatformerSweep.Clear();
    }