Lightning [for free GS]

Posted By: 3run

Lightning [for free GS] - 08/28/10 14:50

I'm using this, example from AUM's Mirrowind:
Code:
VECTOR line_start;
VECTOR line_end;
VECTOR segment_start;
VECTOR segment_end;
var line_length;
var temporary;
var segment_length;
BMAP* effect_tga = "effect.tga";

function fade_lightning(PARTICLE* p)
{
	p.lifespan = 0;
}

function particle_lightning(PARTICLE* p)
{
	VECTOR temp;
	temp.x = random(2) - 1;
	temp.y = random(2) - 1;
	temp.z = random(2) - 1;
	vec_set(p.vel_x, temp);
	p.bmap = effect_tga;
	p.size = 4;
	p.alpha = 100;
	set(p,BRIGHT|MOVE);
	p.lifespan = 1; // the particles live for a single frame
	p.event = fade_lightning;
}

function particle_segment()
{
	vec_set(temporary, segment_end);
	vec_sub(segment_end, segment_start);
	segment_length = vec_length(segment_end);
	segment_end.x = (segment_end.x * 5) / segment_length; // create particles every 5 quants
	segment_end.y = (segment_end.y * 5) / segment_length;
	segment_end.z = (segment_end.z * 5) / segment_length;
	while(segment_length > 0)
	{
		effect(particle_lightning, 1, segment_start.x, nullvector);
		vec_add(segment_start, segment_end);
		segment_length -= 5; // same value here
	}
}
	
function lightning_effect()
{
	vec_set(temporary, line_start);
	vec_sub(line_end, line_start);
	line_length = vec_length(line_end);
	line_end.x = (line_end.x * 100) / line_length; // create segments every 100 quants
	line_end.y = (line_end.y * 100) / line_length;
	line_end.z = (line_end.z * 100) / line_length;
	while(line_length > 0)
	{
		vec_add(line_start, line_end);
		vec_set(segment_start, temporary);
		vec_set(segment_end, line_start);
		segment_end.x += random(20) - 10; // displace the lightning segments (don't make the lightning look like a straight line)
		segment_end.y += random(20) - 10;
		segment_end.z += random(20) - 10;
		particle_segment();
		line_length -= 100; // keep the same value here
	}
}

It's converted in to lite-c by me, works great. The only thing I whant to ask for, is how to make lightning follow fixed start and end positions without lag? It moves after the vertex on the weapon, not with it. Thank you.

© 2023 lite-C Forums