Ejemplo n.º 1
0
    void LateUpdate()
    {
        if (bridge)
        {
            // Get the bridge modifier
            if (mod == null)
            {
                mod = bridge.GetComponent <MegaRopeDeform>();
            }

            if (mesh == null)
            {
                MeshFilter mf = bridge.GetComponent <MeshFilter>();
                mesh = mf.sharedMesh;
            }

            if (mod && mesh)
            {
                int     ax  = (int)mod.axis;
                Vector3 pos = transform.position;

                // Get into local space
                Vector3 lpos = mod.transform.worldToLocalMatrix.MultiplyPoint(pos);

                bool onbridge = true;
                if (checkonbridge)
                {
                    if (lpos.x > mesh.bounds.min.x && lpos.x < mesh.bounds.max.x && lpos.z > mesh.bounds.min.z && lpos.z < mesh.bounds.max.z)
                    {
                        onbridge = true;
                    }
                    else
                    {
                        onbridge = false;
                    }
                }

                // Are we on the bridge
                if (onbridge)
                {
                    // How far across are we
                    float alpha = (lpos[ax] - mod.soft.masses[0].pos.x) / (mod.soft.masses[mod.soft.masses.Count - 1].pos.x - mod.soft.masses[0].pos.x);

                    if (alpha > 0.0f || alpha < 1.0f)
                    {
                        Vector2 rpos = mod.SetWeight(lpos[ax], weight);

                        lpos.y             = rpos.y + (offset * 0.01f);                 // 0.01 is just to make inspector easier to control in my test scene which is obvioulsy very small
                        transform.position = bridge.transform.localToWorldMatrix.MultiplyPoint(lpos);
                    }
                }
                else
                {
                    SetPos(mod, 0.0f);
                }
            }
        }
    }
Ejemplo n.º 2
0
    public float offset = 0.0f;         // Character offset

    //Vector3 lastpos = Vector3.zero;

    void LateUpdate()
    {
        if (bridge)
        {
            // Get the bridge modifier
            if (mod == null)
            {
                mod = bridge.GetComponent <MegaRopeDeform>();
            }

            if (mod)
            {
                int     ax  = (int)mod.axis;
                Vector3 pos = transform.position;

                // Get into local space
                Vector3 lpos = mod.transform.worldToLocalMatrix.MultiplyPoint(pos);

                // Are we on the bridge
                //if ( lpos.x > mod.bbox.min.x && lpos.x < mod.bbox.max.x && lpos.z > mod.bbox.min.z && lpos.z < mod.bbox.max.z )
                //{
                // How far across are we
                //float alpha = (lpos[ax] - mod.bbox.min[ax]) / (mod.bbox.max[ax] - mod.bbox.min[ax]);
                float alpha = (lpos[ax] - mod.soft.masses[0].pos.x) / (mod.soft.masses[mod.soft.masses.Count - 1].pos.x - mod.soft.masses[0].pos.x);

                if (alpha > 0.0f || alpha < 1.0f)
                {
                    //if ( alpha < 0.0f )
                    //	alpha = 0.0f;

                    // Deform the bridge
                    //SetPos(mod, alpha);
                    // Place object on deformed bridge
                    //Vector2 rpos = mod.GetPos3(lpos[ax]);
                    Vector2 rpos = mod.SetWeight(lpos[ax], weight);

                    //lpos[ax] = rpos.x;
                    lpos.y = rpos.y + (offset * 0.01f);                                 // 0.01 is just to make inspector easier to control in my test scene which is obvioulsy very small
                    //lpos.y = mod.GetPos(alpha) + (offset * 0.01f);	// 0.01 is just to make inspector easier to control in my test scene which is obvioulsy very small

                    transform.position = bridge.transform.localToWorldMatrix.MultiplyPoint(lpos);
                }
                //}
                //else
                //{
                //SetPos(mod, 0.0f);
                //}
            }
        }
    }