Ejemplo n.º 1
0
        protected override void OnSimulateStart()
        {
            //BrakeKey = GetKey(Brake);
            HJ        = GetComponent <HingeJoint>();
            Colliders = GetComponentsInChildren <Collider>();
            MyId      = GetComponent <BlockVisualController>().ID;

            angleDrag = GetComponent <Rigidbody>().angularDrag;

            JointLimits jl = HJ.limits;

            jl.min    = jl.max = jl.bounciness = jl.bounceMinVelocity = 0;
            HJ.limits = jl;


            HJ.spring = new JointSpring()
            {
                damper = 10000, spring = 10000, targetPosition = 0
            };

            if (Collider)
            {
                //禁用原有碰撞
                foreach (Collider c in Colliders)
                {
                    if (c.name == "CubeColliders")
                    {
                        c.enabled = false;
                    }
                }

                WheelCollider = new GameObject("Wheel Collider");

                mFilter      = WheelCollider.AddComponent <MeshFilter>();
                mFilter.mesh = WheelMesh = SimpleMesh.MeshFromObj(Application.dataPath + "/Mods/Resources/BlockEnhancement/Wheel.obj");

                mCollider        = WheelCollider.AddComponent <MeshCollider>();
                mCollider.convex = true;

                PM = mCollider.material;

                //静摩擦力
                PM.staticFriction = Friction;
                //动摩擦力
                PM.dynamicFriction = Friction;
                //摩擦力组合
                PM.frictionCombine = PhysicMaterialCombine.Multiply;
                //弹力
                PM.bounciness = 0;
                //弹力组合
                PM.bounceCombine = PhysicMaterialCombine.Minimum;


#if DEBUG
                mRenderer = WheelCollider.AddComponent <MeshRenderer>();
                mRenderer.material.color = Color.red;
#endif

                PaS pas = GetPositionAndScale(MyId);

                WheelCollider.transform.parent     = mCollider.transform.parent = transform;
                WheelCollider.transform.rotation   = mCollider.transform.rotation = transform.rotation;
                WheelCollider.transform.position   = mCollider.transform.position = transform.TransformPoint(transform.InverseTransformPoint(transform.position) + pas.Position);
                WheelCollider.transform.localScale = mCollider.transform.localScale = pas.Scale;
                WheelCollider.AddComponent <DestroyIfEditMode>();
            }
            else if (FrictionT)
            {
                //设置原有碰撞的参数
                foreach (Collider c in Colliders)
                {
                    if (c.name == "CubeColliders")
                    {
                        PhysicMaterial PM = c.GetComponent <BoxCollider>().material;

                        //静摩擦力
                        PM.staticFriction = Friction;
                        //动摩擦力
                        PM.dynamicFriction = Friction;
                        Debug.Log(PM.bounciness);
                        //摩擦力组合
                        PM.frictionCombine = PhysicMaterialCombine.Multiply;
                        //弹力
                        PM.bounciness = 0;
                        //弹力组合
                        PM.bounceCombine = PhysicMaterialCombine.Minimum;
                    }
                }
            }

            if (MyId == (int)BlockType.Wheel || MyId == (int)BlockType.LargeWheel)
            {
                CMCH = GetComponent <CogMotorControllerHinge>();
                CMCH.speedLerpSmooth = Lerp;
            }
        }