Search Unity

Weapon Recoil Questions (Animation vs AddForce, etc)

Discussion in 'Physics' started by SuperGCNBoy, Jun 24, 2017.

  1. SuperGCNBoy

    SuperGCNBoy

    Joined:
    Dec 14, 2013
    Posts:
    11
    Hello, I'm trying to create weapon recoil for a project I'm working on and I've got a few questions about it.

    Is animation or Rigidbody.AddForce() better for creating recoil? I would think using the AddForce() method could result in a more natural look/feel so I'm going to base my next few questions on that.

    What I was thinking of doing was using AddForce to push the weapon up/back, and then a Vector3.Lerp() to smoothly bring the weapon back to its original position.

    I've tried using AddForce but it seems the velocity doesn't decay but rather just keeps what I added.

    I've also looked at AddExplosionForce() since that seems like it would be a good way to launch the weapon up/back a little w/o adding permanent velocity.

    And last question for now. What about setting a pivot point on a GameObject? How could I have the pivot point on the GameObject unaffected by Y forces, but still react to a little Z force, and have the front of the weapon react to both.

    Also, I've heard of HingeJoints, and Springs. Should I be looking at those?

    Thanks, and sorry for the long post!
     
  2. Major

    Major

    Joined:
    Jul 26, 2012
    Posts:
    69
    As far as I know, most shooters use animation to drive weapon recoil and other movements. I wouldn't recommend combining physics with scripted movement because it can cause weird things to happen. Besides that, balancing forces like that is tricky.

    If you want to script the movement, I would recommend only using lerp functions.

    I should mention though, I do not know everything there is to know about this thing, but the simplest solution would be animation, and the simplest solution is almost always the best one.