Realistic 2D Retro/Pixelized Lightning Bolts

$9
Publisher Legit Games
File size 23.62kB
Number of files 7
Latest version 1
Latest release date 2018-08-02 12:04:24
First release date 2018-08-02 12:04:24
Supported Unity versions 2018.4.2 or higher
Easily add realistic looking 2D retro/pixelized lightning bolts to your game!

* Control how wide/narrow and thick/thin your bolt is
* Add realistic branches based on your desired amount (or turn off for a bolt without any branches)
* Adjust the min/max angle and length of your branches
* Change the color to any color you like
* Automatically have your bolt point towards and follow a target collider or local/world position

If you would like to learn how to create these lightning bolts from scratch, sign up for the Udemy course instead. Full source code is included.

Contents of README.txt is shared below:

//
// Lightning Bolt
// Usage Instructions
//

----------

[Usage]

1. Add the "Lightning Bolt" component to your desired game object. (NOTE: If the game object has a Sprite Renderer attached and you do not want its sprite to be overridden by the bolt, you must attach the component to a nested game object instead.)

2. Adjust the "Pixels Per Unit" to match the PPU of your game or to your desired amount (the higher the number, the thinner and less pixelated the bolts will appear).

3. Set "Origin Offset" to your desired local position to offset the starting point of the bolt from the game object it is attached to.

4a. If targeting a static position, use "Target" to set the world position for the bolt to end at. Enabling "Target Is Offset" will use "Target" as a local position instead of a world position.

4b. If targeting a dynamic game object, set "Target Collider" to the physics collider of the desired target in the scene (the bolt will then follow this target as it moves). If the target is spawned dynamically, use the following code to set the value at run-time:

LightningBolt bolt = gameObject.GetComponent<LightningBolt> ();

if (bolt) {
  bolt.targetCollider = targetGameObject
    .GetComponent<Collider2D> ();
}

5. Use "Color" to change the overall color of the bolt.

6. Use "Bolts Per Second" to animate the bolt (the higher the number, the more times the bolt will be regenerated per second; use 0 for a static bolt, or 60 to have the bolt regenerated on every frame, regardless of framerate).

----------

[Advanced Usage]

1. "Split Iterations" determines how many times the bolt is split from a single straight line (the higher the number, the more number of individual lines will appear in your bolt).

2. "Split Offset Divider" determines how wide/narrow the bolt will become (the higher the number, the more narrow the bolt will be). Use "Min/Max Split Offset Multiplier" to fine tune the narrowness by adjusting the amount each line can be offset from its parent line when split (using a min/max amount of 0 will result in a completely straight bolt).

NOTE: The split offset is determined by the total length of the bolt, divided by the "Split Offset Divider", and then multiplied on an individual line basis by a random amount within the "Min/Max Split Offset Multiplier" range.

3. Adjust "Branch Creation Chance" to increase/decrease the amount of branches that appear off of the main bolt (the higher the number, the greater the chance of creating a branch on each split; use 0 for no branches whatsoever, or 1 to have a branch always created).

4. Adjust "Min/Max Branch Angle" to increase/decrease the amount each branch can be rotated from its parent line upon creation.

5. Adjust "Min/Max Branch Length Multiplier" to increase/decrease the min/max length each branch can be (the higher the numbers, the longer the branches will be).

----------

[Tips]

* To change the sorting layer or order of the bolt, attach a Sprite Renderer to the game object and set the sorting layer and order to your desired values. The component will detect that a Sprite Renderer is already attached and render the bolt to its sprite.

----------

Thanks for reading!

Have questions? Send an email to: [email protected]