|
Post by Titon on May 5, 2013 9:51:38 GMT
In this tutorial I'm, going to show you how to make some reasonably impressive fires using the unity engine. All files are provided here:File DownloadLighting Jitter Codeusing UnityEngine; using System.Collections;
public class Lightingjitter : MonoBehaviour { public AnimationCurve IntensityCurve; public AnimationCurve RangeCurve; float frame=0,initialIntensity, initialRange; Light theLight; void Start () { theLight=GetComponent<Light>(); initialIntensity=theLight.intensity; initialRange=theLight.range; } void Update () { frame+=Time.deltaTime; theLight.intensity=initialIntensity*IntensityCurve.Evaluate(frame); theLight.range=initialRange*RangeCurve.Evaluate(frame); } }
To start with import the campfire model into your scene.Then create a new empty Game object called Fire and child it to your campfire .Set its position to 0,0,0 Next add a particle systems component to our Fire object ,and set its rotation to 0,0,0.Go to the Shape tab of the particle system and enter the following This makes the particle system emit particles in a cylinder with a smaller radius so that the particles do not spawn on the rocks of the campfire.Next we modify the starting lifetime and speed so that the particles trail isn't as long Next we want to change the particle material so that we aren't just emitting white particles.Create a new material using the particles/additive shader and set the texture as our fire texture. Then set the particle systems render material to our new flame material Next lets change our particle colour over lifetime to get a more realistic fire colour And also our particle size as the last particles are just popping out of view which looks really unnatural Lastly lets increase the number of particles emitted.You should have your campfire looking as so Now lets add a new point light and child it to our campfire.I've deleted my directional light in the scene so you can see the point light better.Lets change the colour to orange and set shadows to soft shadows .Remember to use the dynamic shadows you must have unity Pro.Go to project setting->player->other settings and change the lighting path from vertex lit or forward rendering to deferred lighting. Now add the Lighting jitter script to the light and set bothtwo curves to the following.This jitters the light so it looks more natural .The large spike corresponds to a fire crackle .Remember to use ping pong settings and extend the animation time if the jitter occurs too fast. Lasty add a new audio source component to the campfire and add the fire wav file and set loop to true You should now have a pretty sexy low complexity fire
|
|