- Home /
Camera does not resume to original Position after Shake
I implemented a camera shake in my 2D game, but after it, the camera does not go back to it's original Position.
public class Shakey : MonoBehaviour
{
public IEnumerator schüttel (float duration , float magnitude)
{
Vector3 originalPos = transform.localPosition;
float elapsed = 0.0f;
while(elapsed < duration)
{
float x = Random.Range(-0.1f, 0.1f) * magnitude;
float y = Random.Range(-1.0f, 0.1f) * magnitude;
transform.localPosition = new Vector3(originalPos.x + x, originalPos.y + y, originalPos.z);
elapsed += Time.deltaTime;
yield return null;
}
transform.localPosition = originalPos;
}
}
the shake is activated by a collision.
Answer by I_Am_Err00r · Sep 04, 2019 at 01:39 PM
I'm not giving you this answer because I know 100% it is true, but I'm giving it because I think it's like 90% true and I don't actually have access to unity to test this for you, but if you change the transform.localPosition to just transform.position, I think that is what you are trying to do.
If it doesn't work and you still need help, just reply to this, let me know what is happening, and when I have access I'll test it out further.
Your answer
Follow this Question
Related Questions
Camera Shaking Problem 0 Answers
Set the default 6d shake noise profile by script in Cinemachine? 0 Answers
How to keep player in screen? 1 Answer
Smooth dizzy camera shake. 0 Answers
Cinemachine Noise Messes Up Isometric Z as Y Tilemap 1 Answer