· gamedev · 3 min read
Black Thorn Prod Challenge 2
Participated in my second challenge with the Youtuber Black Thorn Prod.
Last weekend I participated in my second Black Thorn Prod challenge. If you are not familiar with Black Thorn Prod, it’s a Youtuber that makes game dev challenge videos. Mostly about having many developers work without communicating.
Here is the first one I participated in:
Reading through the comments, it seems people liked my random dancing penguin 😄🐧💃.
This time though, I decided to keep things under control. I focused mainly of improving the existing features. This is the video I sent to BlackThornProd:
Code
The code is pretty simple. But I thought I would note somethings.
Since I’m using a render texture, I want to reset the texture each time a new drawing is spawned. I reset it using the GL (Graphcis Library) API.
1public void ClearOutRenderTexture(RenderTexture renderTexture)2{3 RenderTexture rt = RenderTexture.active;4 RenderTexture.active = renderTexture;5 GL.Clear(true, true, Color.clear);6 RenderTexture.active = rt;7}Something else to note is how to change the properties of a particle system in code. I always forget that I have to change the “main” property. Since it’s a struct we can’t just change the values, so you have to put the value in a variable, make the changes and assign it back.
1public override void ApplyStrokeVariables(Pencil pencil, int strokeCount)2{3 var main = m_ParticleSystem.main;4
5 //Apply Stroke variables6 if (pencil.IsUsingGradient)7 {8 Gradient newGradient = new Gradient();9 newGradient.SetKeys(10 new GradientColorKey[] { new GradientColorKey(pencil.PrimaryColor, 0.0f), new GradientColorKey(pencil.SecondaryColor, 1.0f) },11 new GradientAlphaKey[] { new GradientAlphaKey(pencil.Opacity, 0.0f), new GradientAlphaKey(pencil.Opacity, 1.0f) });12
13 var startColor = main.startColor;14 startColor.mode = ParticleSystemGradientMode.Gradient;15 startColor.gradient = newGradient;16
17 main.startColor = startColor;18 }19 else20 {21 var startColor = main.startColor;22 startColor.mode = ParticleSystemGradientMode.Color;23 var color = pencil.PrimaryColor;24 startColor.color = new Color(color.r, color.b, color.b, pencil.Opacity);25 main.startColor = startColor;26 }27
28 var startSize = main.startSize;29 startSize.constant = pencil.StrokeWidth;30 main.startSize = startSize;31
32 //keep the sortOrder such that each stroke is on top of previous ones.33 m_ParticleSystem.GetComponent<Renderer>().sortingOrder = strokeCount;34}Outro
I enjoyed working on this one, I had a clear idea of the result I wanted and how to achieve it. In the end I probably spent around 3-4hours to implement all those change and around 1-2hours for making the video.
All in all a good interesting weekend project.