Skip to content

Commit

Permalink
Added lightning bolt looking energy transfer effects.
Browse files Browse the repository at this point in the history
  • Loading branch information
LoganBarnett committed Nov 19, 2010
1 parent 0cd3ac2 commit 0d2b6d7
Show file tree
Hide file tree
Showing 38 changed files with 696 additions and 3 deletions.
Binary file added Assets/Materials/Lightning Mat.mat
Binary file not shown.
Binary file modified Assets/Prefabs/Droid.prefab
Binary file not shown.
Binary file modified Assets/Prefabs/Level.prefab
Binary file not shown.
Binary file modified Assets/Scenes/Test.unity
Binary file not shown.
Binary file added Assets/Sounds/Energy Transfer.wav
Binary file not shown.
Binary file added Assets/Textures/Lightning.psd
Binary file not shown.
63 changes: 63 additions & 0 deletions Assets/src/LightningBolt.cs
@@ -0,0 +1,63 @@
/*
This script is placed in public domain. The author takes no responsibility for any possible harm.
Contributed by Jonathan Czeck
*/
using UnityEngine;
using System.Collections;

public class LightningBolt : MonoBehaviour
{
public Transform target;
public int zigs = 100;
public float speed = 1f;
public float scale = 1f;
public Light startLight;
public Light endLight;

Perlin noise;
float oneOverZigs;

private Particle[] particles;

void Start()
{
oneOverZigs = 1f / (float)zigs;
particleEmitter.emit = false;

particleEmitter.Emit(zigs);
particles = particleEmitter.particles;
}

void Update ()
{
if (noise == null)
noise = new Perlin();

float timex = Time.time * speed * 0.1365143f;
float timey = Time.time * speed * 1.21688f;
float timez = Time.time * speed * 2.5564f;

for (int i=0; i < particles.Length; i++)
{
Vector3 position = Vector3.Lerp(transform.position, target.position, oneOverZigs * (float)i);
Vector3 offset = new Vector3(noise.Noise(timex + position.x, timex + position.y, timex + position.z),
noise.Noise(timey + position.x, timey + position.y, timey + position.z),
noise.Noise(timez + position.x, timez + position.y, timez + position.z));
position += (offset * scale * ((float)i * oneOverZigs));

particles[i].position = position;
particles[i].color = Color.white;
particles[i].energy = 1f;
}

particleEmitter.particles = particles;

if (particleEmitter.particleCount >= 2)
{
if (startLight)
startLight.transform.position = particles[0].position;
if (endLight)
endLight.transform.position = particles[particles.Length - 1].position;
}
}
}

0 comments on commit 0d2b6d7

Please sign in to comment.