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 /
  • Help Room /
avatar image
0
Question by Grundadrakk · May 15, 2017 at 05:22 AM · c#cameratransform.positiontransform.rotation

Camerashake doesn´t work expected in Build c#

Hi!

I´m currently working on a script for camera-shaking and zoom, which gets values from some other scripts. But the point is that everything works fine in the editor, if i create a build with it, the shaking is to heavy and i think the float-values are NOT correctly in the build. Maybe you could help me? :)

following is the script:

public Camera cameraAim; public GameObject Target; public Transform posOld; public Transform posNew;

 public float zoomSpeed = 50.0f;
 public float zoomMin = 20.0f;
 public float zoomMax = 80.0f;

 public float zoomMinRun = 25.0f;
 public float zoomMaxRun = 80.0f;

 public float posSpeed = 10.0f;

 public float shake = 0.15f;
 public float shakeDuration = 0.1f;

 public float shakeRot = 5.0f;
 public float smoothAmount = 5.0f;
 public float smoothAmountRun = 5.0f;


 private bool inAiming;
 private bool inRunning;
 private bool inShooting;
 private float zoom;
 private float old_zoom;

 private float timer_shaking;
 private float step;

 private player_management playerManage;
 private player_input playerInput;

 private Vector3 shakeAmountPos;
 private Vector3 shakeAmountRot;


 // Use this for initialization
 void Start() {

     zoom = cameraAim.fieldOfView;
     old_zoom = cameraAim.fieldOfView;

 }

 // Update is called once per frame
 void Update()
 {
     playerManage = Target.GetComponent<player_management>();
     playerInput = Target.GetComponent<player_input>();
     inAiming = playerManage.inAiming;
     inRunning = playerInput.in_running;
     inShooting = playerInput.in_shooting;


     timer_shaking += Time.deltaTime;
     step = Time.deltaTime * posSpeed;

     if ((inAiming == true) || (inRunning == true))
     {
         zoom -= Time.deltaTime * zoomSpeed;
         if (inRunning == true)
         {
             zoom = Mathf.Clamp(zoom, zoomMinRun, zoomMaxRun);
             cameraAim.transform.position = Vector3.MoveTowards(cameraAim.transform.position, posNew.transform.position, step);
             cameraAim.transform.position = cameraAim.transform.position + shakeAmountPos;
             cameraAim.transform.localRotation = Quaternion.Lerp(cameraAim.transform.localRotation, Quaternion.Euler(shakeAmountRot), Time.deltaTime * smoothAmountRun);
         }
         else
         {
             zoom = Mathf.Clamp(zoom, zoomMin, zoomMax);
             cameraAim.transform.position = Vector3.MoveTowards(cameraAim.transform.position, posOld.transform.position, step);
         }
     }
     else
     {
         cameraAim.transform.position = Vector3.MoveTowards(cameraAim.transform.position, posOld.transform.position, step);
         cameraAim.transform.rotation = posOld.transform.rotation;
         zoom += Time.deltaTime * zoomSpeed;
         zoom = Mathf.Clamp(zoom, zoomMin, old_zoom);
     }

     //Die Position und Rotation verändert sich erst nach überlaufen der festgelegten Zeit
     if (timer_shaking > shakeDuration)
     {
         shakeAmountPos = Random.insideUnitSphere * shake;
         shakeAmountPos.z = 0.0f;

         shakeAmountRot = Random.insideUnitSphere * shake * shakeRot;  

         timer_shaking = 0.0f;
     }

     //Veränderung während dem Schießen
     if (inShooting == true)
     {
         cameraAim.transform.position = cameraAim.transform.position + shakeAmountPos;
         cameraAim.transform.localRotation = Quaternion.Lerp(cameraAim.transform.localRotation, Quaternion.Euler(shakeAmountRot), Time.deltaTime * smoothAmount);
     }

 }

 private void LateUpdate()
 {
     cameraAim.fieldOfView = Mathf.Lerp(cameraAim.fieldOfView, zoom, Time.deltaTime * zoomSpeed);
 }

}

Comment
Add comment · Show 1
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 Grundadrakk · May 14, 2017 at 06:26 PM 0
Share

solved the problem

problem was that ive given the "cameraAim.transform.position" three times the value of the shakeAmountPos. Deleting this lines solved it. $$anonymous$$aybe someone use this after fit this script to unchaos $$anonymous$$e

delete line 93 & 63

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

130 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

Related Questions

Mathf.Clamp does not work correctly in trannsform.position I'm trying to create a 2.5D game but I'm having trouble limiting camera movement 0 Answers

Question about Screen to World Point 0 Answers

Rotation around player. and Camera position, 2 Answers

Simple Camera Switch Using C# 3 Answers

Determine camera distance for object to be completely visible 2 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