- Home /
How can my window shake while im running?
HI there how can I make my camera shake while im running? I mean rotating...Im using the FPS input controller. Im a newbie with unity....
Answer by syclamoth · Feb 16, 2012 at 08:48 AM
In this case, I think that moving the camera around would work better than rotation. In the simplest case, I'd make the camera a child of a 'shaker' object, that randomly moves around whenever the screenshake is active. You might want to include some damping, but in the simplest form, it goes like this:
transform.localPosition = Random.insideUnitSphere * shakePower;
where shakePower is a float between 0 and infinity.
To damp it, have the position interpolate between points ever few tenths of a second.
currentShakeTime += Time.deltaTime * shakeSpeed;
transform.localPosition = Vector3.Lerp(previousPos, nextPos, currentShakeTime);
if(currentShakeTime >= 1)
{
previousPos = nextPos;
nextPos = Random.insideUnitSphere * shakePower;
currentShakeTime = 0;
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613064132im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
iTween.ShakePosition freezes Rotation 0 Answers
Loop a script ? 0 Answers
Is it possible to shake the camera? 4 Answers
Can't move Camera Position using Script 2 Answers
Shake and move at the same time 0 Answers