문제

I'm creating a 2D game with OpenGL ES for Android.I want to perform a shake effect.

My idea is changing my camera's y coordinate but i'm not sure about algorithm.I have a position vector with x and y variables for my camera class.

도움이 되었습니까?

해결책

Looks like a duplicate of Opengl Real world Camera Shake algorithm . Essentially model the shaking after a Sin wave and modulate the amplitude depending on how much you want the camera to shake.

a really basic outline like below, you'll need to stop this when amplitude hits 0 among other things..

private float amplitude = 10.0f;
private float adjustAmplitudePerSecond = -1.0f;
private float timeElapsed = 0.0f;

public void shake(float deltaTime) {
    timeElapsed += deltaTime;
    amplitude += adjustAmplitudePerSecond * deltaTime;
    yourCamera.y += + Math.sin(timeElapsed);
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top