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);
}
}
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
Your answer
Follow this Question
Related Questions
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