I am trying to create a rock’em sock’em robots like game. I am working on the boxing motion. Right now I just have a box as the player and a smaller box as the fist (no arm). To punch forward I can just use addForce
to the fist, then on contact I can transfer forces and simulate knock back…I think. I maybe misunderstanding how to addForce
, please correctly if I’m wrong. But, if I am right, does anyone know how to use this method to replicate something that is not strait on like a right hook?
AddForce you can think of as an invisible block pulling or pushing a Rigidbody (correct me if I’m wrong). I think the best scenario is that you use the AddForce on the fist of the person that is punching, and just use plain old colliders and rigidbodies for the knockback (just let the built in physics take its place). If you need help with the addforce on the fist, just make a script that will go on the fist, and inside add this:
public Rigidbody fistRigidbody;
public Vector3 punchForce;
void Update() {
if (Input.GetMouseButtonDown(0)) {
fistRigidbody.AddForce(punchForce);
}
}
You can change the parameters in the inspector. You need to put the rigidbody of the fist into the blank and then add a force to the vector 3. The punch force is world coordinates so if his fist is facing down or up, they will still both punch in the same direction instead of based on their rotation. Hope I helped!
public Rigidbody fistRigidbody;
public Vector3 punchForce;
void Update() {
if (Input.GetMouseButtonDown(0)) {
fistRigidbody.AddForce(punchForce);
}