private void OnCollisionEnter(Collision collision) { Vector3 collision_impulse = collision.impulse; Vector3 collision_relativeVelocity = collision.relativeVelocity; Rigidbody bodyA = GetComponent <Rigidbody>(); // self Rigidbody bodyB = collision.rigidbody; // other float bodyA_mass = bodyA?.mass ?? 0f; float bodyB_mass = bodyB?.mass ?? 0f; float bodyA_angularDrag = bodyA?.angularDrag ?? 0f; float bodyB_angularDrag = bodyB?.angularDrag ?? 0f; Vector3 bodyA_angularVelocity = bodyA?.angularVelocity ?? Vector3.zero; Vector3 bodyB_angularVelocity = bodyB?.angularVelocity ?? Vector3.zero; float bodyA_drag = bodyA?.drag ?? 0f; float bodyB_drag = bodyB?.drag ?? 0f; Vector3 bodyA_inertiaTensor = bodyA?.inertiaTensor ?? Vector3.zero; Vector3 bodyB_inertiaTensor = bodyB?.inertiaTensor ?? Vector3.zero; var CVA = ColliderVolume.Attach(gameObject); var CVB = ColliderVolume.Attach(collision.gameObject); float bodyA_volume = CVA?.Volume ?? 0f; float bodyB_volume = CVB?.Volume ?? 0f; float bodyA_surfaceArea = CVA?.SurfaceArea ?? 0f; float bodyB_surfaceArea = CVB?.SurfaceArea ?? 0f; //Renderer renderA = GetComponent<Renderer>( ) ?? GetComponentInChildren<Renderer>(); //Renderer renderB = collision.gameObject.GetComponent<Renderer>( ) ?? collision.gameObject.GetComponentInChildren<Renderer>(); }
public void OnCollisionEnter(Collision collision) { lastCollision = collision; selfVol = selfVol ?? ColliderVolume.Attach(gameObject); body = body ?? GetComponent <Rigidbody>() ?? GetComponentInParent <Rigidbody>(); //y0 = 0; //Stiffness = 0; //Damping = 0; //Frequency = 0; // -- Rigid Body -- var bD = body.drag; var bAD = body.angularDrag; var bM = body.mass; // -- Physics Material -- // How bouncy is the surface? A value of 0 will not bounce. A value of 1 will bounce without any loss of energy. float mB = collision.collider.material.bounciness; // The friction used when already moving. This value is usually between 0 and 1. float mF = collision.collider.material.dynamicFriction; // The friction coefficient used when an object is lying on a surface. float mSF = collision.collider.material.staticFriction; // -- Volume / Area -- // Combined Volume of all the colliders attached float oV = selfVol.Volume; // Combined Surface area of all the colliders attached float oSA = selfVol.SurfaceArea; // -- Collision variables -- // The total impulse applied to this contact pair to resolve the collision. Vector3 cI = collision.impulse; // The relative linear velocity of the two colliding objects Vector3 cV = collision.relativeVelocity; // Total sum of the distance between the colliders at the contact point. float cST = collision.GetSeparationTotal(); // Avarage point of all contacts Vector3 cP = collision.GetAvarageContactPoint(); // Avarage normalized "normal" value of all contact points Vector3 cN = collision.GetAvarageContactNormal(); // -- Normalize -- var velocity_normalized = cV.magnitude / 350f; // 50 on avarage var volume_normalized = oV / 27f; // For a a unit calpsule the avarage value is 10 var surfaceArea_normalized = oSA / 27f; // For a unit capsule the avarage value is 10 var impulseMagnitude_normalize = cI.magnitude / 150f; // strong impule magnitude is around 30 //VolumeMultiplier = impulseMagnitude_normalize; //var contactPoint_normalized = cST; Damping = 0.012f - (0.01f * impulseMagnitude_normalize); values[globalIndex] = Mathf.Abs(cI.magnitude); //Mass = bM / 60f; // Viscous damping force is a formulation of the damping phenomena, in which the source of damping force is modeled as a function of the volume, shape, and velocity of an object traversing through a real fluid with viscosity.[1] //Damping = Play(true); }