Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

FPS Predictable Weapon Recoil

Discussion in 'Scripting' started by Cnc96, Aug 3, 2015.

  1. Cnc96

    Cnc96

    Joined:
    Dec 17, 2013
    Posts:
    57
    Hi all,

    I'm looking at creating a small FPS game that has similar weapon mechanics to Counter Strike: Global Offensive where weapons have a predictable weapon spread.

    I am wondering if anyone has any links to scripts, tutorials, or forum posts that would help with creating a similar system?
     
  2. Strategos

    Strategos

    Joined:
    Aug 24, 2012
    Posts:
    255
    Assuming your are firing raycasts for your bullets, then just alter the angle by a small random amount.

    Give weapons a value, the smaller it is the tighter the cluster, multiply the value if walking or running.

    Jobs a good un.
     
  3. Cnc96

    Cnc96

    Joined:
    Dec 17, 2013
    Posts:
    57
    That was my original thought, but would there be a way to get it to get it to produce the same pattern every time?
    A bit like the CS:GO spreads where weapons will produce a pattern like those in the link all the time?
    http://csgoskills.com/academy/spray-patterns/
     
  4. Strategos

    Strategos

    Joined:
    Aug 24, 2012
    Posts:
    255
    Ok this is recoil.

    Keep the weapon spread as described above.

    But every-time the player fires their gun move their aim (ie the camera ) a small amount.

    it seems that the guns in counterstrike have a random up amount, and a random left / right amount. When they reach a maximum vertical value they stop going up and recoil left and right.

    You are going to have to give each gun a "personality" using several variables. For instance.

    Vertical recoil amount per shot. say 0.1f - 0.2f
    Maximum vertical recoil. say 10 or 15.
    Horizontal recoil amount : say -0.1f to 0.1f
    Horizontal recoil multiplier after max vertical recoil reached. 2.0f

    that way you could have guns that kick hard upwards then hard left and right after a set amount of shots.

    guns which kick left and right and up all the time

    guns which kick up then hold at the top, all sorts.
     
    vlvaseha and a-t-hellboy like this.
  5. Cnc96

    Cnc96

    Joined:
    Dec 17, 2013
    Posts:
    57
    Man, you are a star!!! That should help a lot, thanks :D