G’day,
I have in place a rather nice means to generate a starfield effect in a 2D top-down shoot-em-up, which generates new particle as the camera moves and destroys out of range particles. The particles have an unlimited lifespan and do not move. This all works grand.
I discovered that by changing the Render Mode of the particles from Billboard to Stretched Billboard, and setting the camera scale, the particles would stretch as the speed of the camera movement increased. This looks awesome when whizzing about, but at low speeds they have a noticeable flicker. I’ve narrowed the cause down to the nature in which velocity is calculated, or rather when, but I’m not sure how to fix it.
I run the following code to position my camera (the actual code I’m using is much more elaborate, to zoom out and look ahead as speed increases - again, it works fine, but it is not necessary to replicate the problem here):
transform.position = new Vector3(body.position.x, 100, body.position.z);
Debug.Log(this.GetComponent<Camera>().velocity.magnitude);
Where body is the Rigidbody of the player spaceship, and the script is a Component of the camera.
So I’ve tried changing where this occurs, going through all the Update modes (Update, FixedUpdate, LateUpdate). The image below shows the magnitude of the velocity of the camera after adjusting its position for each update type:
Okay, so the velocity has a lot of gaps. That explains the flickering. The question is, what can I do to fix this?
Cheers!