• 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 /
  • Help Room /
avatar image
0
Question by SwirlyBitz · Apr 20, 2015 at 06:14 AM · c#cameratransformfirstpersoncontrollerfirstperson

Headbob is not working after camera shaking c# Firstperson

Hi! I'm making a first person game so i use the free asset package from the Unity. My problem is i put camera shaking script inside the camera of my first person character because in my game there is a situation that the ground will shake and you're going to die. The Camera shaking script is working and the game looks like the environment is shaking but after the shaking of the camera the HeadBob is not working anymore when i run. The headbob is working before the camera shaking when i run. I dont know how to fix it because i just placed the asset package and the first person character into my scene and play it.

 public Transform camTransform;
     
     // How long the object should shake for.
     public float shake = 0f;
     
     // Amplitude of the shake. A larger value shakes the camera harder.
     public float shakeAmount = 0.7f;
     public float decreaseFactor = 1.0f;
     
     Vector3 originalPos;
 
     void Awake()
     {
         if (camTransform == null)
         {
             camTransform = GetComponent(typeof(Transform)) as Transform;
         }
     }
     
     void OnEnable()
     {
         originalPos = camTransform.localPosition;
     }
     
     void Update()
     {
 
         if (CoffeemakingButton.ShouldCameraShake)
         {
             if (shake > 0) {
                 camTransform.localPosition = originalPos + Random.insideUnitSphere * shakeAmount;
                 shake -= Time.deltaTime * decreaseFactor;
             } else {
                 shake = 0f;
                 camTransform.localPosition = originalPos;
             }
         }
 
     }
Comment
Add comment · Show 2
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
avatar image AlwaysSunny · Apr 20, 2015 at 06:03 AM 1
Share

See my answer to this question about a similar issue: http://answers.unity3d.com/questions/949984/slight-leantilt-when-strafing-messes-up-mouselook.html

Besides anything else that's going on, you should add a level of abstraction separating input behavior from additional behaviors like shake, head bob, etc.

Isolating individual mechanical operations into their own distinct logic will make it easier to build, expand, and spot issues.

WRT your specific issue, if something works before an operation, and doesn't work after, trace down the problem using print() statements to report the status of variables to ensure they are what you expect them to be. Clearly you are inadvertently overriding the head-bob behavior with something you're doing to achieve shake-on-demand behavior. Placing these functions in the same script would be wise.

avatar image SwirlyBitz · Apr 20, 2015 at 02:41 PM 0
Share

I got errors to your link please help me

Sorry, but the question you're trying to see was deleted. We're sorry, but you do not have permission to do the activity you attempted. If you believe this to be in error, please contact the site ad$$anonymous$$istrator(s).

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by WinterboltGames · Sep 09, 2016 at 01:32 AM

My Friend Just Go And Import The Character From Assets>Import>Characters And Boom It's Fixed!!!

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
avatar image
0

Answer by WinterboltGames · Sep 09, 2016 at 01:33 AM

My Friend Just Go And Import The Character From Assets>Import>Characters And Boom It's Fixed!!!

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Rotate camera when colliding 0 Answers

Underwater Swimming 2 Answers

Camera isn't move position? Why my camera isn't change position? 0 Answers

2D Player bounds problem based on moving camera 0 Answers

How to get the position of the Main Camera 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