Submissions from 2017-11-17 to 2017-11-18 (1 total)

Lack of motivation to tackle any substantial task today, I decided to spend a few hours investigating what it might take to make my water cannon look a little bit more watery.

Prior to today, my cannon basically shot projectiles that had simple trail renderers on them. Things kinda sorta looked decent when you fired a bunch in the same basic spot, but, once you started moving the cannon, instead of a stream of water, you saw a bunch of individual shots of water with long tails.

Today's work involved hacking around with the Unity LineRenderer. Unfortunately, it's a bit cumbersome to work with. To render a line, you basically need to give it an array of Vector3 every frame. It'll then connect the dots. Additionally, each LineRenderer can only draw one contiguous line. Need a few streams of water? You need a few LineRenderer gameObjects.

This led me to create a WaterManager class. When the Water Cannon is fired, a projectile is fired. This projectile registers itself with the WaterManager. When the projectile dies, it unregisters itself. In turn, each frame the water manager scans through the list of all the projectiles it knows about. Projectiles that are 'close enough' to each other get all their positions lumped into a Vector3 array. This process ultimately produces a list of Vector3 arrays (one array for each clump of projectiles). Each array of Vector3 then gets assigned to a LineRenderer object.

The results? Something that looks like a constant stream of water... Well, really more like a stream of silly string. But, something that looks better than what I had before. Additionally, when the middle of that stream of water hits an object or when the projectiles in that stream get too far apart from each other, the stream dynamically breaks into two (or more) streams.

Ultimately, it's still not perfect and, if nothing else, can probably be refactored to be a bit more efficient. But, for now, I'm calling it an improvement.