Esempio n. 1
0
        // Calculating the impulse magnitude from a collision
        private float GetImpulse(MuscleCollision m)
        {
            float i = m.collision.impulse.sqrMagnitude;

            // Collision threshold
            if (collisionThreshold > 0f)
            {
                float mlp = PuppetMasterSettings.instance != null? (1f + PuppetMasterSettings.instance.currentlyActivePuppets * PuppetMasterSettings.instance.activePuppetCollisionThresholdMlp): 1f;
                if (i < collisionThreshold * mlp)
                {
                    return(0f);
                }
            }

            i *= 0.04f;             // Coeficient for evening out for pre-0.3 versions

            // Collision resistance multipliers
            foreach (CollisionResistanceMultiplier crm in collisionResistanceMultipliers)
            {
                if (LayerMaskExtensions.Contains(crm.layers, m.collision.collider.gameObject.layer))
                {
                    if (crm.multiplier <= 0f)
                    {
                        i = Mathf.Infinity;
                    }
                    else
                    {
                        i /= crm.multiplier;
                    }
                    break;
                }
            }

            return(i);
        }
Esempio n. 2
0
        // Calculating the impulse magnitude from a collision
        private float GetImpulse(MuscleCollision m, ref float layerThreshold)
        {
            float i = m.collision.impulse.sqrMagnitude;

            i /= puppetMaster.muscles [m.muscleIndex].rigidbody.mass;
            i *= 0.3f;             // Coeficient for evening out for pre-0.3 versions

            // Collision resistance multipliers
            foreach (CollisionResistanceMultiplier crm in collisionResistanceMultipliers)
            {
                if (LayerMaskExtensions.Contains(crm.layers, m.collision.collider.gameObject.layer))
                {
                    if (crm.multiplier <= 0f)
                    {
                        i = Mathf.Infinity;
                    }
                    else
                    {
                        i /= crm.multiplier;
                    }

                    layerThreshold = crm.collisionThreshold;

                    break;
                }
            }

            return(i);
        }
Esempio n. 3
0
		// Calculating the impulse magnitude from a collision
		private float GetImpulse(MuscleCollision m) {
			float i = m.collision.impulse.sqrMagnitude;

			// Collision threshold
			if (collisionThreshold > 0f) {
				float mlp = PuppetMasterSettings.instance != null? (1f + PuppetMasterSettings.instance.currentlyActivePuppets * PuppetMasterSettings.instance.activePuppetCollisionThresholdMlp): 1f;
				if (i < collisionThreshold * mlp) return 0f;
			}

			i *= 0.04f; // Coeficient for evening out for pre-0.3 versions

			// Collision resistance multipliers
			foreach (CollisionResistanceMultiplier crm in collisionResistanceMultipliers) {
				if (LayerMaskExtensions.Contains(crm.layers, m.collision.collider.gameObject.layer)) {
					if (crm.multiplier <= 0f) i = Mathf.Infinity;
					else i /= crm.multiplier;
					break;
				}
			}
			/*
			// MuscleProps collision resistance multipliers
			BehaviourPuppet.MuscleProps props = GetProps(puppetMaster.muscles[m.muscleIndex].props.group);
			foreach (CollisionResistanceMultiplier crm in props.collisionResistanceMultipliers) {
				if (LayerMaskExtensions.Contains(crm.layers, m.collision.collider.gameObject.layer)) {
					Debug.Log("Here");
					if (crm.multiplier <= 0f) i = Mathf.Infinity;
					else i /= crm.multiplier;
					break;
				}
			}
			*/
			
			return i;
		}
Esempio n. 4
0
        protected override void OnMuscleCollisionBehaviour(MuscleCollision m)
        {
            if (!enabled)
            {
                return;
            }

            // If the muscle has collided with something that is on the PuppetMaster's collision layers.
        }
Esempio n. 5
0
 private void OnPreMuscleCollisionExit(MuscleCollision c)
 {
     if (!LayerMaskExtensions.Contains(groundLayers, c.collision.gameObject.layer))
     {
         return;
     }
     groundContacts[c.muscleIndex]      = false;
     groundContactPoints[c.muscleIndex] = Vector3.zero;
 }
Esempio n. 6
0
        public void OnMuscleCollisionExit(MuscleCollision collision)
        {
            if (!initiated)
            {
                return;
            }
            if (OnPreMuscleCollisionExit != null)
            {
                OnPreMuscleCollisionExit(collision);
            }

            OnMuscleCollisionExitBehaviour(collision);

            if (OnPostMuscleCollisionExit != null)
            {
                OnPostMuscleCollisionExit(collision);
            }
        }
Esempio n. 7
0
        private void OnPreMuscleCollision(MuscleCollision c)
        {
            if (!LayerMaskExtensions.Contains(groundLayers, c.collision.gameObject.layer))
            {
                return;
            }
            if (c.collision.contacts.Length == 0)
            {
                return;
            }
            lastGroundedTime = Time.time;

            groundContacts[c.muscleIndex] = true;
            if (mode == Mode.CenterOfPressure)
            {
                groundContactPoints[c.muscleIndex] = GetCollisionCOP(c.collision);
            }
        }
Esempio n. 8
0
		// When a muscle collides with something (called by the MuscleCollisionBroadcaster component on the muscle).
		protected override void OnMuscleCollisionBehaviour(MuscleCollision m) {
			// All the conditions for ignoring this
			if (!enabled) return;
			if (state == State.Unpinned) return;
			if (collisions > maxCollisions) return;
			if (!LayerMaskExtensions.Contains(collisionLayers, m.collision.gameObject.layer)) return;
			if (masterProps.normalMode == NormalMode.Kinematic && !puppetMaster.isActive && !masterProps.activateOnStaticCollisions && m.collision.gameObject.isStatic) return;

			// Get the collision impulse on the muscle
			float impulse = GetImpulse(m);
			if (impulse <= 0f) return;
			collisions ++;

			// Try to find out if it collided with another puppet's muscle
			if (m.collision.collider.attachedRigidbody != null) {	
				broadcaster = m.collision.collider.attachedRigidbody.GetComponent<MuscleCollisionBroadcaster>();
				if (broadcaster != null) {
					if (broadcaster.muscleIndex < broadcaster.puppetMaster.muscles.Length) {
						// Multiply impulse (if the other muscle has been boosted)
						impulse *= broadcaster.puppetMaster.muscles[broadcaster.muscleIndex].state.impulseMlp;

						float stayF = m.isStay? 0.05f: 0.1f;
						broadcaster.puppetMaster.muscles[broadcaster.muscleIndex].offset -= m.collision.impulse * Time.deltaTime * stayF;

						/*
						float velocityF = puppetMaster.muscles[m.muscleIndex].rigidbody.velocity.sqrMagnitude / broadcaster.puppetMaster.muscles[broadcaster.muscleIndex].rigidbody.velocity.sqrMagnitude;
						velocityF = Mathf.Clamp(velocityF, 0.5f, 2f);
						//velocityF = 1f + (velocityF - 1f) * 0.5f;
						impulse /= velocityF;
						*/
					}
				}
			}

			// Should we activate the puppet?
			if (Activate(m.collision, impulse)) puppetMaster.mode = PuppetMaster.Mode.Active;

			// Let other scripts know about the collision
			if (OnCollisionImpulse != null) OnCollisionImpulse(m, impulse);

			// Unpin the muscle (and other muscles)
			UnPin(m.muscleIndex, impulse);
		}
Esempio n. 9
0
 protected virtual void OnMuscleCollisionExitBehaviour(MuscleCollision collision)
 {
 }
Esempio n. 10
0
        // When a muscle collides with something (called by the MuscleCollisionBroadcaster component on the muscle).
        protected override void OnMuscleCollisionBehaviour(MuscleCollision m)
        {
            if (OnCollision != null)
            {
                OnCollision(m);
            }

            // All the conditions for ignoring this
            if (!enabled)
            {
                return;
            }
            if (state == State.Unpinned)
            {
                return;
            }
            if (collisions > maxCollisions)
            {
                return;
            }
            if (!LayerMaskExtensions.Contains(collisionLayers, m.collision.gameObject.layer))
            {
                return;
            }

            if (LayerMaskExtensions.Contains(groundLayers, m.collision.gameObject.layer))
            {
                if (state == State.GetUp)
                {
                    return;                       // Do not damage if contact with ground layers and in getup state
                }
                if (puppetMaster.muscles[m.muscleIndex].props.group == Muscle.Group.Foot)
                {
                    return;                                                                       // Do not damage if feet in contact with ground layers
                }
            }
            if (masterProps.normalMode == NormalMode.Kinematic && !puppetMaster.isActive && !masterProps.activateOnStaticCollisions && m.collision.gameObject.isStatic)
            {
                return;
            }

            // Activate on Kinematic-Kinematic pair
            if (puppetMaster.muscles[m.muscleIndex].rigidbody.isKinematic && m.collision.collider.attachedRigidbody != null && m.collision.collider.attachedRigidbody.isKinematic)
            {
                if (masterProps.normalMode == NormalMode.Kinematic && puppetMaster.mode == PuppetMaster.Mode.Kinematic)
                {
                    puppetMaster.mode = PuppetMaster.Mode.Active;
                }
            }
            else
            {
                // Get the collision impulse on the muscle
                float cT      = collisionThreshold;
                float impulse = GetImpulse(m, ref cT);

                float minImpulseMlp = PuppetMasterSettings.instance != null ? (1f + PuppetMasterSettings.instance.currentlyActivePuppets * PuppetMasterSettings.instance.activePuppetCollisionThresholdMlp) : 1f;
                float minImpulse    = cT * minImpulseMlp;

                if (impulse <= minImpulse)
                {
                    return;
                }
                collisions++;

                // Try to find out if it collided with another puppet's muscle
                if (m.collision.collider.attachedRigidbody != null)
                {
                    broadcaster = m.collision.collider.attachedRigidbody.GetComponent <MuscleCollisionBroadcaster>();
                    if (broadcaster != null)
                    {
                        if (broadcaster.muscleIndex < broadcaster.puppetMaster.muscles.Length)
                        {
                            // Multiply impulse (if the other muscle has been boosted)
                            impulse *= broadcaster.puppetMaster.muscles[broadcaster.muscleIndex].state.impulseMlp;

                            //float stayF = m.isStay? 0.05f: 0.1f;
                            //broadcaster.puppetMaster.muscles[broadcaster.muscleIndex].offset -= m.collision.impulse * Time.deltaTime * stayF;
                        }
                    }
                }

                // DO not move this up, the impulse value will be wrong.
                // Let other scripts know about the collision (even the ones below collision threshold)
                if (OnCollisionImpulse != null)
                {
                    OnCollisionImpulse(m, impulse);
                }

                // Should we activate the puppet?
                if (Activate(m.collision, impulse))
                {
                    puppetMaster.mode = PuppetMaster.Mode.Active;
                }

                // Unpin the muscle (and other muscles)
                UnPin(m.muscleIndex, impulse);
            }
        }