Search Unity

Recoil Patters Instead of Random Recoil For FPS Game

Discussion in 'Scripting' started by _spacepig_, Jan 8, 2017.

  1. _spacepig_

    _spacepig_

    Joined:
    Jan 18, 2016
    Posts:
    151
    Hi, I am currently working on a skill based, competitive multiplayer FPS (although i've barely started) and I would like the recoil to not be random so a player cannot "get luckey". I would like the recoil to have patters like csgo.

    Example of pattern:

    Camera rotates up 5 x the curves to the right then back, or something like that.

    I do want the patterns to be easy to edit in the inspector. Perhaps Animation Curve variable could take part?

    C# only plz and make sure the solution makes it easy to change Patterns. Thank you!!!'
     
  2. LoganPark

    LoganPark

    Joined:
    Aug 30, 2013
    Posts:
    23
    Well, I don't suppose I can provide a complete solution remotely, but it sounds like you want to put something like this in the gun's script?

    Code (csharp):
    1.  
    2. public float muzzleJumpAngle = 5.0f;
    3. public float muzzleTurnRatio = 0.2f;
    4.  
    5. void Update() {
    6.     if( Input.GetMouseDown(0) { //left click start
    7.  
    8.         //Your actual gun firing code goes here first, (maybe include a foreach loop for burst fire) then:
    9.  
    10.         Camera.main.transform.eulerAngles = new Vector3( Camera.main.transform.eulerAngles.x + muzzleJumpAngle, Camera.main.transform.eulerAngles.y + muzzleJumpAngle / 5.0f, 0.0f);
    11.     }
    12. }
    13.  
     
  3. _spacepig_

    _spacepig_

    Joined:
    Jan 18, 2016
    Posts:
    151
    yes i would like it to be in the gun script


    But... 2 things are a problem


    First...
    It needs to be smooth
    (I can do that myself with lerp)

    Second...
    I need the patters to be a bit more complex...

    Example.. rotate x 7 then 3 y the -3 y then maybe x 2 then back to zero


    You could take a look at counterstrike go's recoil patterns

    Thanks for the help though
     
  4. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,531
    Oh... right away sir, what ever you say sir, we're here to do your bidding.
     
    bewky and TaleOf4Gamers like this.
  5. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,531
    Also, why not just use animations, then your code just picks which animation to play from an array.

    You get the built in unity animation editor to create animations that way.
     
  6. _spacepig_

    _spacepig_

    Joined:
    Jan 18, 2016
    Posts:
    151
    k all try this now