Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 MaxPlite · Apr 17, 2019 at 08:57 PM · fpsweaponscamera rotationrecoil

How to make Recoil Dampening aka. Recentering?

So i have a system that makes camera move after shot (basic recoil system) It only goes to a certain pre-defined point with use of Slerp function (to make it look smoother) yet doesn't go back to the point where camera was initially facing -> it goes up but after that it doesn't go down.
At first all of this was made intentionally but now i want to add the Recentering (aka camera moving back some amount of time after to where it was facing before shooting)
There is the original code with mouse input sampling and applying recoil to then send it to script performing rotation (i cutout some parts to make it clearer):

 private void Update()
 {
     // Mouse X rotation (Y axis) + Recoil Y axis
     float _yRot = Input.GetAxisRaw("Mouse X");
     _rotation = new Vector3(0.0f, _yRot, 0.0f) * lookIntens;
     _rotation.y += cameraRecoil.y;
  
     // Mouse Y rotation (X axis) + Recoil X axis
     float _xRot = Input.GetAxisRaw("Mouse Y");
     _camRotationX = _xRot * lookIntens;
     _camRotationX += cameraRecoil.x;
  
     // Setting cameraRecoil value
     cameraRecoil = Vector3.Slerp(cameraRecoil, Vector3.zero, 0.25f);

     // Applying to PlayerMotor
     motor.Rotate(_rotation);
     wepRotating.WepRotatorY(_yRot);
     motor.RotateCamera(_camRotationX);
     wepRotating.WepRotatorX(_xRot);
 }

 public void GetRecoilValue(Vector3 _cameraRecoil)
 {
     cameraRecoil = _cameraRecoil;
 }

Where "cameraRecoil" is a semi-random Vector3 value received after each shot from another script operating on various stats of different weapons ;
"motor" and "wepRotating" are script to which im sending values to perform certain actions

I was trying a few things like subtracting cameraRecoil from the current camera rotation or accumulating cameraRecoil values from Slerp function and waiting till cameraRecoill is low enough so i could rotate it back.
However as it should work for both automatic weapons (where consecutive shots make it so previous cameraRecoil value doesnt have enough time to apply fully before receiving next value and new rotation is performed while previous Slerped value is fe. halfway to zero) and for slow firing ones (where the recentering speed and time after which it is performed is pretty important) there was always a flaw where either camera went to much (on full-autos) or too little down (on semis)
Now the question is how do i make the camera behave so it can work when cameraRecoil is fully Slerped and not? Or is there another way of making recoil recentering?

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

0 Replies

· Add your reply
  • Sort: 

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.

Follow this Question

Answers Answers and Comments

140 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Camera Recoil,Please help me. 2 Answers

FPS Weapon inventory script help 0 Answers

Managing different weapons in scripting. 4 Answers

Swapping Weapons In Game 0 Answers

Adding objects on player models in a multiplayer game 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges