• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by paradoxstudios · Sep 28, 2016 at 03:26 PM · fpsrecoil

Help with more realistic camera recoil

Hello. This is a problem i've been having quite a while. My goal is to achieve a realistic (or more realistic) camera recoil effect, similar to that of Insurgency. The current camera recoil effect I have is quite good, but it is also quite lacking. The main problem with it is the jitter. When you look at it, it is rough, and doesn't look very natural. As well as that, if you're getting a high framerate, your recoil will be very small, but if you have a low frame rate, there will be more recoil, and it will be jumping a lot more. This method has the recoil happening in a single frame, and the return to center is done over time.

Here is a video showing off this camera recoil system

https://youtu.be/rbnxgRM4Qjk

This is the code I have used to handle it private Vector3 CameraRecoil1; private float shoottime;

     void Update () {
         Recoil2();
 
         Transform cameraClimb = generalSettings.cameraClimbHolder.transform;
         string fireMode = weaponSettings.CurrentWeapon.fireMode.ToString();
 
         //For Pistols
         if (fireMode == "Semi")
             if (Input.GetButtonDown("Fire1"))
                 Shoot();
             else
                 CameraRecoil1 = Vector3.Lerp(CameraRecoil1, new Vector3(0, 0, 0), Time.deltaTime * cameraRecoil.z / 6f);
 
         //For Rifles
         if (fireMode == "Auto")
             if (Input.GetButton("Fire1"))
                 Shoot();
             else
                 CameraRecoil1 = Vector3.Lerp(CameraRecoil1, new Vector3(0, 0, 0), Time.deltaTime * cameraRecoil.z / 4f);
     }
 
     void Shoot ()
     {
         if (shoottime <= Time.time && !isBusy && !isReloading && !isRunning)
         {
             shoottime = Time.time + weaponSettings.CurrentWeapon.fireRate;
 
             WeaponInfo currentWeapon = weaponSettings.CurrentWeapon;
             Vector3 cameraRecoil = weaponSettings.CurrentWeapon.cameraRecoil;
 
             CameraRecoil1 = Vector3.Lerp(CameraRecoil1, new Vector3(-cameraRecoil.x, Random.Range(-cameraRecoil.y, cameraRecoil.y), Random.Range(-cameraRecoil.z / 2f, cameraRecoil.z / 2f)), Time.deltaTime * cameraRecoil.z);
         }
     }
 
     void Recoil2 ()
     {
         Vector3 cameraRecoil = weaponSettings.CurrentWeapon.cameraRecoil;
         Transform cameraClimb = generalSettings.cameraClimbHolder.transform;
 
         cameraClimb.localEulerAngles = CameraRecoil1;
     }

This is somewhat not the result I am aiming for. I have tried other methods, where rather than it happening in a single frame, it happens over a short time, but this looks too artificial and the weapon looks like it's just being rotated up. Here is a video of the assault rifle camera recoil effect i'd like to achieve

https://www.youtube.com/watch?v=GVcdADx6PbU

Does anyone have any idea how I could achieve this effect?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Diglett · Sep 29, 2016 at 02:08 PM

Another way to do it, would be to Lerp the position of the camera to a position you want. This would be smoother. Once the player stops firing, slowly lerp it back down. Something like that.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to make Recoil Dampening aka. Recentering? 0 Answers

Camera Recoil,Please help me. 2 Answers

Adding some recoil to the Camera (FPS) 1 Answer

Recoil problem 0 Answers

FPS recoil, lerp fighting 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges