• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
jokoon

How would you simulate gun recoil in a FPS ?

1 post in this topic

My goal is to remake the counter strike recoil feel, especially for automatic guns, and I'm having an hard time.

I was told on math.stackexchange with this function [url="https://www.google.fr/search?aq=f&ix=hcb&ie=UTF-8&q=plot+5x*e%5E(1-5x)+from+0+to+1"]https://www.google.fr/search?aq=f&ix=hcb&ie=UTF-8&q=plot+5x*e%5E(1-5x)+from+0+to+1[/url]
which sort of simulate some sort of impulse, to tweak its quickness I just have to change '5' to something else, and it still results with something between 0 and 1.

For single shots it behave quite nicely, but with automatic guns in counter strike, the recoil sort of accumulate and adds up to an higher angle.

Any idea with some kind of equation or algorithm ?
0

Share this post


Link to post
Share on other sites
First you need some kind of construct to ensure your recoil never exceeds a given value, so your angle doesn't grow to infinity. One such construct is:

[b]Recoil = 1 - 1 / (1 + impulse power)[/b]

This way Recoil will always be between 0 and 1. It will be zero when the impulse power is zero, and it will tend to 1 as the power increases. The function behaves like this:

[url="http://www.wolframalpha.com/input/?i=plot+y+%3D+1+-+1+%2F+%281+%2B+x%29+from+x+%3D+0+to+5"]http://www.wolframal...om+x+%3D+0+to+5[/url]

Raising the (1 + power) term to higher powers will lead to faster recoil accumulation, but it will still remain between zero and one. Lower powers will similarly lead to slower recoil accumulation. Of course, don't use negative powers, or.. it doesn't work anymore. And make sure your power is never negative either. You can tweak those exponents for different guns, i.e. a Uzi probably will have a low exponent whereas a sniper rifle will have a big one.

At that point you have a recoil factor between zero and one, you can then scale it, and perhaps add a small initial angle so your shots at zero impulse power aren't spot on.

As for impulse power, you can simply keep a counter, increase it for each shot fired, and decrease it by a little each frame (clamping it to zero), this way recoil will gradually fade if you stop shooting. Of course you could be more elaborate by using exponential decay to model that, but that's off topic.

Now you can obviously use another function (even the one you suggested in your post) but you will need to use some form of smooth clamping to prevent the recoil becoming unrealistically big. And hard-clamping it doesn't really work well, it's pretty noticeable from a user point of view.
0

Share this post


Link to post
By the looks of the plot in the link you provided, the curve looks right to what you said. I changed the 5 in the exponent to 9 and got the spike I think you are referring to. To cut a long story short, unless you have a downward force applied through whatever physics engine you use, it won't work. However it works perfectly fine if you simply limit the y with whatever you get for the result. So each gun can have a different limit. This would be up to you and how you are processing the recoil. Don't change the curve, the algorithm is fine. Just don't forget, that if you later want to use more accurate physics for the character (ie. 3rd person view), you are getting a visual translation as opposed to a gravity calculation.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0