GlowImposter Script

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
m (Text replace - "<javascript>" to "<syntaxhighlight lang="javascript">")
m (Text replace - "</javascript>" to "</syntaxhighlight>")
Line 52: Line 52:

Latest revision as of 20:52, 10 January 2012

Author: Forest (yoggy)

[edit] Description

This script uses a flat plane to generate a cool graphical effect that mimics a glowing volume by rotating and scaling a plane with a circle texture on it. This can be used for glowing bullets, lasers etc.

[edit] Usage

Use this script on both a flat plane object with an Additive shader and circle texture and a blank object that parents the flat plane. Set the "parent" variable accordingly.

[edit] JavaScript - GlowImposter.js

var parent = true;
private var normalScale = Vector3(0, 0, 0);
function Update ()
	target = Camera.main.transform;
	// Get the rotation tword the camera
	vector = target.position - transform.position;
	/* parent should be true on the blank game object that parents the flat plane object
	parent should be false on the flat plane object parented by the blank object*/
		// rotate the parent's z axis toward the camera
		vector.z = 0;
		transform.rotation = Quaternion.FromToRotation (Vector3.up, vector);
		// rotate the child object's x axis toward the camera
		z = vector.normalized.z;
		if(normalScale == normalScale = transform.localScale;
		transform.localEulerAngles.x = z * 90;
		// get a range for relative z distance
		z = Mathf.Abs(z);
		z = 1 - z;		
		// scale by relative z distance
		transform.localScale.z = z * normalScale.z;
		transform.localScale.z += normalScale.x;
Personal tools