コード例 #1
0
        void SetFriction(float value, PhysicMaterialCombine combine)
        {
            collider.material.dynamicFriction = value;
            collider.material.staticFriction  = value;

            collider.material.frictionCombine = combine;
        }
コード例 #2
0
 public PhysicMaterialSerializable(PhysicMaterial material) : base(material)
 {
     bounciness      = material.bounciness;
     dynamicFriction = material.dynamicFriction;
     staticFriction  = material.staticFriction;
     frictionCombine = material.frictionCombine;
     bounceCombine   = material.bounceCombine;
 }
コード例 #3
0
    static int IntToEnum(IntPtr L)
    {
        int arg0 = (int)LuaDLL.lua_tonumber(L, 1);
        PhysicMaterialCombine o = (PhysicMaterialCombine)arg0;

        LuaScriptMgr.PushEnum(L, o);
        return(1);
    }
コード例 #4
0
 public override void Deserialize(BinaryReader binaryReader)
 {
     base.Deserialize(binaryReader);
     bounceCombine   = (PhysicMaterialCombine)binaryReader.ReadInt32();
     bounciness      = binaryReader.ReadSingle();
     dynamicFriction = binaryReader.ReadSingle();
     frictionCombine = (PhysicMaterialCombine)binaryReader.ReadInt32();
     staticFriction  = binaryReader.ReadSingle();
 }
コード例 #5
0
		/// <summary>
		/// 	Calculates the bounce of two surfaces colliding. Returns zero if the
		/// 	bounce is below the bounce threshold.
		/// </summary>
		/// <param name="bounceA">Bounce a.</param>
		/// <param name="bounceB">Bounce b.</param>
		/// <param name="velocityA">Velocity a.</param>
		/// <param name="velocityB">Velocity b.</param>
		/// <param name="combine">Combine.</param>
		public static float CombineBounce(float bounceA, float bounceB, Vector3 velocityA, Vector3 velocityB,
										  PhysicMaterialCombine combine)
		{
			Vector3 relativeVelocity = velocityA - velocityB;
			if (relativeVelocity.magnitude < UnityEngine.Physics.bounceThreshold)
				return 0.0f;

			return Combine(bounceA, bounceB, combine);
		}
        protected override void ReadFromImpl(object obj)
        {
            base.ReadFromImpl(obj);
            PhysicMaterial uo = (PhysicMaterial)obj;

            bounciness      = uo.bounciness;
            dynamicFriction = uo.dynamicFriction;
            staticFriction  = uo.staticFriction;
            frictionCombine = uo.frictionCombine;
            bounceCombine   = uo.bounceCombine;
        }
コード例 #7
0
 /// <summary>
 /// コンストラクタ
 /// </summary>
 /// <param name="physicMaterial">PhysicMaterialオブジェクト</param>
 public PhysicMaterialKun(PhysicMaterial physicMaterial) : base(physicMaterial)
 {
     if (physicMaterial != null)
     {
         bounceCombine   = physicMaterial.bounceCombine;
         bounciness      = physicMaterial.bounciness;
         dynamicFriction = physicMaterial.dynamicFriction;
         frictionCombine = physicMaterial.frictionCombine;
         staticFriction  = physicMaterial.staticFriction;
     }
 }
コード例 #8
0
        /// <summary>
        ///     Calculates the bounce of two surfaces colliding. Returns zero if the
        ///     bounce is below the bounce threshold.
        /// </summary>
        /// <param name="bounceA">Bounce a.</param>
        /// <param name="bounceB">Bounce b.</param>
        /// <param name="velocityA">Velocity a.</param>
        /// <param name="velocityB">Velocity b.</param>
        /// <param name="combine">Combine.</param>
        public static float CombineBounce(float bounceA, float bounceB, Vector3 velocityA, Vector3 velocityB,
                                          PhysicMaterialCombine combine)
        {
            Vector3 relativeVelocity = velocityA - velocityB;

            if (relativeVelocity.magnitude < UnityEngine.Physics.bounceThreshold)
            {
                return(0.0f);
            }

            return(Combine(bounceA, bounceB, combine));
        }
コード例 #9
0
        private void UpdateGroundContact()
        {
            if (this.part.GroundContact)
            {
                if (!groundHit)
                {
                    KAS_Shared.DebugLog(
                        "UpdateGroundContact(Anchor) - Part hit ground ! Set part friction to : "
                        + dynamicFriction);
                    orgBounciness      = this.part.collider.material.bounciness;
                    orgDynamicFriction = this.part.collider.material.dynamicFriction;
                    orgStaticFriction  = this.part.collider.material.staticFriction;
                    orgFrictionCombine = this.part.collider.material.frictionCombine;
                    this.part.collider.material.bounciness      = bounciness;
                    this.part.collider.material.dynamicFriction = dynamicFriction;
                    this.part.collider.material.staticFriction  = staticFriction;
                    this.part.collider.material.frictionCombine = PhysicMaterialCombine.Maximum;

                    KAS_Shared.DebugLog("UpdateGroundContact(Anchor) - Set part drag to : " + groundDrag);
                    orgAngularDrag         = this.part.angularDrag;
                    orgMaximum_drag        = this.part.maximum_drag;
                    orgMinimum_drag        = this.part.minimum_drag;
                    this.part.angularDrag  = groundDrag;
                    this.part.maximum_drag = groundDrag;
                    this.part.minimum_drag = groundDrag;

                    groundHit = true;
                }
            }
            else
            {
                if (groundHit)
                {
                    KAS_Shared.DebugLog(
                        "UpdateGroundContact(Anchor) - Part hit ground ! Set part material to"
                        + " (Bou,dfrict,sfrict,combine) : " + orgBounciness + " | " + orgDynamicFriction
                        + " | " + orgStaticFriction + " | " + orgFrictionCombine);
                    this.part.collider.material.bounciness      = orgBounciness;
                    this.part.collider.material.dynamicFriction = orgDynamicFriction;
                    this.part.collider.material.staticFriction  = orgStaticFriction;
                    this.part.collider.material.frictionCombine = orgFrictionCombine;

                    KAS_Shared.DebugLog("UpdateGroundContact(Anchor) - Set part drag to (Ang,max,min) : "
                                        + orgAngularDrag + " | " + orgMaximum_drag + " | " + orgMinimum_drag);
                    this.part.angularDrag  = orgAngularDrag;
                    this.part.maximum_drag = orgMaximum_drag;
                    this.part.minimum_drag = orgMinimum_drag;

                    groundHit = false;
                }
            }
        }
コード例 #10
0
        //Generic methods
        private void Awake()
        {
            //Grab components
            material          = GetComponent <Collider>().material;
            attachedRigidbody = GetComponent <Rigidbody>();
            controller        = GetComponent <FirstPersonCharacterController>();

            //Grab original values
            originalSpeed           = controller.moveSpeed;
            originalSFriction       = material.staticFriction;
            originalDFriction       = material.dynamicFriction;
            originalFrictionCombine = material.frictionCombine;
        }
コード例 #11
0
ファイル: Ball.cs プロジェクト: Dremand/BeTheDodgeBall
    float CalculateFrictionCoefficient(EFrictionType frictionType)
    {
        float frictionCoefficient = 0.0f;

        //determine our friction values
        Collider coll                    = GetComponent <Collider>();
        float    ourFriction             = (frictionType == EFrictionType.EFT_Static) ? coll.material.staticFriction : coll.material.dynamicFriction;
        PhysicMaterialCombine ourCombine = coll.material.frictionCombine;

        //check if we are colliding against an object
        Vector3 ourPosition     = transform.position;
        float   ourHeight       = transform.localScale.y;
        float   ourGroundBuffer = 0.25f;

        int layer     = LayerMask.NameToLayer("Ball");
        int layerMask = 1 << layer;

        layerMask = ~layerMask;
        RaycastHit hit;

        if (Physics.Raycast(ourPosition, -Vector3.up, out hit, (ourHeight * 0.5f) + ourGroundBuffer, layerMask))
        {
            float hitFriction = (frictionType == EFrictionType.EFT_Static) ? hit.collider.material.staticFriction : hit.collider.material.dynamicFriction;
            PhysicMaterialCombine hitCombine = hit.collider.material.frictionCombine;
            //Average < Minimum < Multiply < Maximum
            bool isMax      = hitCombine == PhysicMaterialCombine.Maximum || ourCombine == PhysicMaterialCombine.Maximum;
            bool isMultiply = hitCombine == PhysicMaterialCombine.Multiply || ourCombine == PhysicMaterialCombine.Multiply;
            bool isMin      = hitCombine == PhysicMaterialCombine.Minimum || ourCombine == PhysicMaterialCombine.Minimum;
            bool isAverage  = hitCombine == PhysicMaterialCombine.Average || ourCombine == PhysicMaterialCombine.Average;

            if (isMax)
            {
                frictionCoefficient = hitFriction > ourFriction ? hitFriction : ourFriction;
            }
            else if (isMultiply)
            {
                frictionCoefficient = hitFriction * ourFriction;
            }
            else if (isMin)
            {
                frictionCoefficient = hitFriction < ourFriction ? hitFriction : ourFriction;
            }
            else if (isAverage)
            {
                frictionCoefficient = (hitFriction + ourFriction) * 0.5f;
            }
        }

        return(frictionCoefficient);
    }
コード例 #12
0
		/// <summary>
		/// 	Returns the resulting PhysicMaterialCombine for two colliding physics materials.
		/// 
		/// 	Maximum > Multiply > Minimum > Average
		/// </summary>
		/// <returns>The resulting physic material combine.</returns>
		/// <param name="combineA">Combine a.</param>
		/// <param name="combineB">Combine b.</param>
		public static PhysicMaterialCombine ResultingPhysicMaterialCombine(PhysicMaterialCombine combineA,
																		   PhysicMaterialCombine combineB)
		{
			if (combineA == PhysicMaterialCombine.Maximum || combineB == PhysicMaterialCombine.Maximum)
				return PhysicMaterialCombine.Maximum;

			if (combineA == PhysicMaterialCombine.Multiply || combineB == PhysicMaterialCombine.Multiply)
				return PhysicMaterialCombine.Multiply;

			if (combineA == PhysicMaterialCombine.Minimum || combineB == PhysicMaterialCombine.Minimum)
				return PhysicMaterialCombine.Minimum;

			return PhysicMaterialCombine.Average;
		}
コード例 #13
0
        private void FrictionToggle(bool value)
        {
            PhysicMaterialCombine physicMaterialCombine = value ? PhysicMaterialCombine.Average : PhysicMaterialCombine.Maximum;

            //设置地形的摩擦力合并方式
            if (GameObject.Find("Terrain Terraced") != null)
            {
                foreach (var v in GameObject.Find("Terrain Terraced").GetComponentsInChildren <MeshCollider>())
                {
                    v.sharedMaterial.frictionCombine = physicMaterialCombine;
                    v.sharedMaterial.bounceCombine   = physicMaterialCombine;
                    break;
                }
            }
        }
コード例 #14
0
ファイル: KASModuleAnchor.cs プロジェクト: ACCBizon/KAS
        private void UpdateGroundContact()
        {
            if (this.part.GroundContact)
            {
                if (!groundHit)
                {
                    KAS_Shared.DebugLog("UpdateGroundContact(Anchor) - Part hit ground ! Set part friction to : " + dynamicFriction);
                    orgBounciness = this.part.collider.material.bounciness;
                    orgDynamicFriction = this.part.collider.material.dynamicFriction;
                    orgStaticFriction = this.part.collider.material.staticFriction;
                    orgFrictionCombine = this.part.collider.material.frictionCombine;
                    this.part.collider.material.bounciness = bounciness;
                    this.part.collider.material.dynamicFriction = dynamicFriction;
                    this.part.collider.material.staticFriction = staticFriction;
                    this.part.collider.material.frictionCombine = PhysicMaterialCombine.Maximum;

                    KAS_Shared.DebugLog("UpdateGroundContact(Anchor) - Set part drag to : " + groundDrag);
                    orgAngularDrag = this.part.angularDrag;
                    orgMaximum_drag = this.part.maximum_drag;
                    orgMinimum_drag = this.part.minimum_drag;
                    this.part.angularDrag = groundDrag;
                    this.part.maximum_drag = groundDrag;
                    this.part.minimum_drag = groundDrag;
    
                    groundHit = true;
                }
            }
            else
            {
                if (groundHit)
                {
                    KAS_Shared.DebugLog("UpdateGroundContact(Anchor) - Part hit ground ! Set part material to (Bou,dfrict,sfrict,combine) : " + orgBounciness + " | " + orgDynamicFriction + " | " + orgStaticFriction + " | " + orgFrictionCombine);
                    this.part.collider.material.bounciness = orgBounciness;
                    this.part.collider.material.dynamicFriction = orgDynamicFriction;
                    this.part.collider.material.staticFriction = orgStaticFriction;
                    this.part.collider.material.frictionCombine = orgFrictionCombine;
           
                    KAS_Shared.DebugLog("UpdateGroundContact(Anchor) - Set part drag to (Ang,max,min) : " + orgAngularDrag + " | " + orgMaximum_drag + " | " + orgMinimum_drag);
                    this.part.angularDrag = orgAngularDrag;
                    this.part.maximum_drag = orgMaximum_drag;
                    this.part.minimum_drag = orgMinimum_drag;
                    
                    groundHit = false;
                }
            }
        }
コード例 #15
0
		/// <summary>
		/// 	Combines the surface values.
		/// </summary>
		/// <returns>The combined surface value.</returns>
		/// <param name="surfaceA">Surface a.</param>
		/// <param name="surfaceB">Surface b.</param>
		/// <param name="combine">Combine.</param>
		public static float Combine(float surfaceA, float surfaceB, PhysicMaterialCombine combine)
		{
			switch (combine)
			{
				case PhysicMaterialCombine.Average:
					return (surfaceA + surfaceB) / 2.0f;

				case PhysicMaterialCombine.Maximum:
					return HydraMathUtils.Max(surfaceA, surfaceB);

				case PhysicMaterialCombine.Minimum:
					return HydraMathUtils.Min(surfaceA, surfaceB);

				case PhysicMaterialCombine.Multiply:
					return surfaceA * surfaceB;

				default:
					throw new ArgumentOutOfRangeException();
			}
		}
コード例 #16
0
        /// <summary>
        ///     Combines the surface values.
        /// </summary>
        /// <returns>The combined surface value.</returns>
        /// <param name="surfaceA">Surface a.</param>
        /// <param name="surfaceB">Surface b.</param>
        /// <param name="combine">Combine.</param>
        public static float Combine(float surfaceA, float surfaceB, PhysicMaterialCombine combine)
        {
            switch (combine)
            {
            case PhysicMaterialCombine.Average:
                return((surfaceA + surfaceB) / 2.0f);

            case PhysicMaterialCombine.Maximum:
                return(HydraMathUtils.Max(surfaceA, surfaceB));

            case PhysicMaterialCombine.Minimum:
                return(HydraMathUtils.Min(surfaceA, surfaceB));

            case PhysicMaterialCombine.Multiply:
                return(surfaceA * surfaceB);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
コード例 #17
0
ファイル: VCI_vci.cs プロジェクト: oocytanb/VCI
        public static string GetStringFromCombine(PhysicMaterialCombine combine)
        {
            switch (combine)
            {
            case PhysicMaterialCombine.Average:
                return(AverageCombine);

            case PhysicMaterialCombine.Minimum:
                return(MinimumCombine);

            case PhysicMaterialCombine.Maximum:
                return(MaximumCombine);

            case PhysicMaterialCombine.Multiply:
                return(MultiplyCombine);

            default:
                return(AverageCombine);
            }
        }
コード例 #18
0
        /// <summary>
        ///     Returns the resulting PhysicMaterialCombine for two colliding physics materials.
        ///
        ///     Maximum > Multiply > Minimum > Average
        /// </summary>
        /// <returns>The resulting physic material combine.</returns>
        /// <param name="combineA">Combine a.</param>
        /// <param name="combineB">Combine b.</param>
        public static PhysicMaterialCombine ResultingPhysicMaterialCombine(PhysicMaterialCombine combineA,
                                                                           PhysicMaterialCombine combineB)
        {
            if (combineA == PhysicMaterialCombine.Maximum || combineB == PhysicMaterialCombine.Maximum)
            {
                return(PhysicMaterialCombine.Maximum);
            }

            if (combineA == PhysicMaterialCombine.Multiply || combineB == PhysicMaterialCombine.Multiply)
            {
                return(PhysicMaterialCombine.Multiply);
            }

            if (combineA == PhysicMaterialCombine.Minimum || combineB == PhysicMaterialCombine.Minimum)
            {
                return(PhysicMaterialCombine.Minimum);
            }

            return(PhysicMaterialCombine.Average);
        }
コード例 #19
0
    public void SetRestitutionCombine(int value)
    {
        switch (value)
        {
        case 0:
            m_restitutionCombine = PhysicMaterialCombine.Average;
            break;

        case 1:
            m_restitutionCombine = PhysicMaterialCombine.Multiply;
            break;

        case 2:
            m_restitutionCombine = PhysicMaterialCombine.Maximum;
            break;

        case 3:
            m_restitutionCombine = PhysicMaterialCombine.Minimum;
            break;
        }
    }
コード例 #20
0
        protected override void switchToPhysics()
        {
            if (FromSlideController)
            {
                pilotTransform = pilot.transform;
                pilotBody      = pilot.GetComponent <Rigidbody>();
                SlideControllerListener component = pilotBody.GetComponent <SlideControllerListener>();
                if (component != null)
                {
                    component.SlideController = this;
                }
                mode               = Mode.PhysicsDriven;
                elapsedTime        = 0f;
                curSpringVel       = 0f;
                originalDrag       = pilotBody.drag;
                pilotBody.velocity = Vector3.zero;
                spawnParticles();
            }
            else
            {
                base.switchToPhysics();
            }
            pilot.layer    = LayerMask.NameToLayer("NoncollidingTube");
            pilotBody.drag = myMutableData.RaceTrackProperties.Drag;
            Collider component2 = pilot.GetComponent <Collider>();

            if (component2 != null)
            {
                physicMaterial = component2.material;
                if (physicMaterial != null)
                {
                    bounciness                   = physicMaterial.bounciness;
                    physicMaterialCombine        = physicMaterial.bounceCombine;
                    physicMaterial.bounciness    = myMutableData.Bounciness;
                    physicMaterial.bounceCombine = myMutableData.BounceCombine;
                }
            }
        }
コード例 #21
0
ファイル: Grain.cs プロジェクト: yeagob/ParticlePack
    //===================================================================

    //===================================================================
    public PhysicMaterial buildPhysicsMaterial(float dynamicFriction, float staticFriction, float bounciness, PhysicMaterialCombine frictionCombine, PhysicMaterialCombine bounceCombine)
    {
        PhysicMaterial physicsMaterial = new PhysicMaterial();

        physicsMaterial.dynamicFriction = dynamicFriction;
        physicsMaterial.staticFriction  = staticFriction;
        physicsMaterial.bounciness      = bounciness;
        physicsMaterial.frictionCombine = frictionCombine;
        physicsMaterial.bounceCombine   = bounceCombine;
        return(physicsMaterial);
    }
コード例 #22
0
 /// <summary>
 ///     Combines the friction of two surfaces.
 /// </summary>
 /// <returns>The combined friction.</returns>
 /// <param name="frictionA">Friction a.</param>
 /// <param name="frictionB">Friction b.</param>
 /// <param name="combine">Combine.</param>
 public static float CombineFriction(float frictionA, float frictionB, PhysicMaterialCombine combine)
 {
     return(Combine(frictionA, frictionB, combine));
 }
コード例 #23
0
 // Change the physics material properties of the character controller
 private void ChangeFriction(float amount, PhysicMaterialCombine combine)
 {
     _physicMaterial.frictionCombine = combine;
     _physicMaterial.staticFriction  = amount;
 }
コード例 #24
0
 /// <summary>
 /// Changes Physics Materials properties.
 /// </summary>
 /// <param name="_ammount">Static Friction ammount.</param>
 /// <param name="_combine">Physic Material Combine type.</param>
 private void ChangeFriction(float _ammount, PhysicMaterialCombine _combine)
 {
     m_physicMaterial.frictionCombine = _combine;
     m_physicMaterial.staticFriction  = _ammount;
 }
コード例 #25
0
    public PhysicMaterial SetupPhysicMaterial(float bounciness, float dynamicFriction, float staticFriction, PhysicMaterialCombine frictionCombine = PhysicMaterialCombine.Average)
    {
        if (collider == null)
        {
            throw new FutileException("must have collider before adding physicMaterial");
        }

        PhysicMaterial physicMaterial = new PhysicMaterial();

        physicMaterial.bounciness      = bounciness;
        physicMaterial.dynamicFriction = dynamicFriction;
        physicMaterial.staticFriction  = staticFriction;
        physicMaterial.frictionCombine = frictionCombine;
        collider.material = physicMaterial;
        return(physicMaterial);
    }
コード例 #26
0
		/// <summary>
		/// 	Combines the friction of two surfaces.
		/// </summary>
		/// <returns>The combined friction.</returns>
		/// <param name="frictionA">Friction a.</param>
		/// <param name="frictionB">Friction b.</param>
		/// <param name="combine">Combine.</param>
		public static float CombineFriction(float frictionA, float frictionB, PhysicMaterialCombine combine)
		{
			return Combine(frictionA, frictionB, combine);
		}
コード例 #27
0
        private static PhysicMaterial SetPhysicMaterial(float friction, float bounciness, PhysicMaterialCombine combine)
        {
            PhysicMaterial PM = new PhysicMaterial
            {
                //静摩擦力
                staticFriction = friction,
                //动摩擦力
                dynamicFriction = friction,
                //弹力
                bounciness = bounciness,
                //摩擦力组合
                frictionCombine = combine,
                //弹力组合
                bounceCombine = PhysicMaterialCombine.Average
            };

            return(PM);
        }
コード例 #28
0
    public PhysicMaterial SetupPhysicMaterial(float bounciness, float dynamicFriction, float staticFriction, PhysicMaterialCombine frictionCombine = PhysicMaterialCombine.Average)
    {
        if (collider == null) throw new FutileException("must have collider before adding physicMaterial");

        PhysicMaterial physicMaterial = new PhysicMaterial();
        physicMaterial.bounciness = bounciness;
        physicMaterial.dynamicFriction = dynamicFriction;
        physicMaterial.staticFriction = staticFriction;
        physicMaterial.frictionCombine = frictionCombine;
        collider.material = physicMaterial;
        return physicMaterial;
    }