How to make a heavy bag (for punching ) heavier ?
Im making a game in VR in which I punch a boxing heavy bag with gloves . I have a Configurable joint on it is attached (at the anchor) a heavy bag . In the heavy bag object I have a rigidbody with a maximum amount of mass but its still not heavy enough as It gets punched it should barely move . I dont wont to add drag to the heavy bag as it makes it very unrealistic.
I tried adding a script to the gloves which check the moment the gloves collide with the bag and tried to downplay the force that is generated by the punching, but that doesn`t work either . The script is BagPunchScript (only the collider code):
void OnCollisionEnter(Collision other) {
Rigidbody otherR = other.gameObject.GetComponent<Rigidbody>();
//check the impact angle
Vector3 avgPoint = Vector3.zero;
foreach (ContactPoint p in other.contacts)
{
avgPoint += p.point;
}
avgPoint /= other.contacts.Length;
Vector3 dir = (avgPoint - transform.position).normalized;
otherR.AddForceAtPosition(dir * 0.01f * rBody.velocity.magnitude, avgPoint); //downplay the force of the hit
if (other == null)
return;
}
Any suggestions ?
Quite a stupid comment from my end, but did you try reducing the mass of the player / gloves ?
Add a debug.log to that: I suspect it is being invoked multiple times. Since the real gloves are not affected by the virtual heavy-bag, you may need to take special measure to ensure the impact- force is transferred to the heavy-bag only once.
Also, might want to give Force$$anonymous$$ode.Impulse (optional parameter for AddForceAtPosition) a shot.
edit: oh.. just spotted this.. you probably want to check (other==null -> return) at the TOP of this function, BEFORE you use it.
I looked at the Force$$anonymous$$ode.Impulse unity documetation and I having problem understaing how to implement it for my use case. Have you got any experience with it ? Tnx
To use impulse mode simply add the optional parameter for the AddForce function eg.
otherR.AddForceAtPosition(dir * 0.01f * rBody.velocity.magnitude, avgPoint, Force$$anonymous$$ode.Impulse); // added optional param after the avgPoint param
Based on my physics classes, an impulse will apply a force only once, over a single moment in time, as opposed to applying the force over a time period. The documentation is certainly not very clear on this, and I'm not sure it will work in your case- but since it's so easy to try out, suggest giving it a shot.
Also, were you able to confirm the force is only applied once, per punch?
Answer by YetAnotherKen · Aug 25, 2019 at 10:16 PM
Meishin has it right. I remember seeing in a training video that the physics engine calculates how much two masses can affect each other based on their relative mass. So, to make the gloves make the bag move less you lower their mass. Or if you are just applying force to the bag, then reduce the amount of force being used.
I tried lowering the mass of the gloves to o.oooo1 and the mass of the bag to 100000, its still the same force applied. Note that the gloves are kinematic. I`m strating to think that my configurable joint (to which the bag is attached ) is the problem somehow ?