Particle moves with an Entity on a vertex

Posted By: JoGa

Particle moves with an Entity on a vertex - 02/06/12 10:29

Hey!
I have a questiona about particles.
My Particle Function moves the particle relativ with an entity.
The example from particles.c helped me.
But I need a additon, I can't do myself because I don't know how I should do that:
The particle is created on a vertex of the entity.
This entity is animated, so the function as it is, does not fit 100%.

How is it possible, to "tell" the particle to take the vertex-position?
The function "effect" does not have a return value lik the ent_create-function has.
Otherwise I could use this return value as a pointer and give him the vertexnumber as a skill p.skill70 for example.

Here is my code so far, I hope, somebody does understand my problem and can help me.
Code:
function p_flammen_in(PARTICLE *p)
{
	p.alpha += p.skill_a*time_step;
	if (p.alpha >= 15) p.bmap  = pct_p_fire02;
	if (p.alpha >= 30) p.bmap  = pct_p_fire01;
	//if (p.alpha >= 50) p.event = p_flammen_out;
	if(!you) return; // example from particles.c
	if(p.skill_x != 0)
	{ 
		vec_add(p.x,your.x);
		vec_sub(p.x,p.skill_x);
	}
	vec_set(p.skill_x,your.x); // store old "you" position
}
function p_condition_burning(PARTICLE* p)
{
	vec_add(p.vel_x,vector(random(2)-1,random(2)-1,0));
	set(p, MOVE | BRIGHT | TRANSLUCENT);
	p.alpha = random(10);
	p.bmap = pct_p_fire03;
	p.size = 20+random(5);
	p.gravity = - 0.4;
	p.skill_a = 8+random(4); // fade factor
	p.event = p_flammen_in;
}


// in a while-loop to circle through the vertices
vec_for_vertex(temp.x, my, integer(random(gesamt_vertices)));
effect(p_condition_burning,15,temp.x,NULL);


Posted By: EvilSOB

Re: Particle moves with an Entity on a vertex - 02/06/12 15:26

Nope.

I dont understand your problem, but I try and help anyway...

Try explaining again, in a different way, what you want.


If you mean that you just want to pass the vertex-number to the effect,
try this...
Code:
function p_flammen_in(PARTICLE *p)
{	... NO CHANGES ...	}

function p_condition_burning(PARTICLE* p)
{
	vec_for_vertex(p.skill_x, you, p.x);      //get THE vertex position
	vec_set(p.x, p.skill_x);                  //put particle there
	...
	ALL ELSE UNCHANGED
	...
}


// in a while-loop to circle through the vertices
effect(p_condition_burning, 15, vector(integer(random(gesamt_vertices)),0,0), NULL);

Is this what you mean?


Code:
function p_flammen_in(PARTICLE *p)
{	... NO CHANGES ...	}

function p_condition_burning(PARTICLE* p)
{
	vec_for_vertex(p.skill_x, you, integer(random(p.x)));      //get A vertex position
	vec_set(p.x, p.skill_x);                                   //put particle there
	...
	ALL ELSE UNCHANGED
	...
}


// in a while-loop to circle through the vertices
effect(p_condition_burning, 15, vector(gesamt_vertices,0,0), NULL);

Or maybe this...


What is the 'visual' effect you are trying to create?
Posted By: JoGa

[solved] Re: Particle moves with an Entity on a vertex - 02/06/12 19:18

Thanks for your help.
ok, I try it again: The particle should move itself, but not in worldposition but in a relativ position to a defined vertex of a model (for example, every particle have to circle around his defined vertex).

MasterQ32 helped me and gave me some code, too.
It workes now; that way: The particle fades in and stay on the vertex.
So if the entity is animated, the entity is covered with the particles. After fading in, the particle fades out and is not attached on the vertex any more, so if the animation goes on and the entity is moving, it leaves a cloud behind it.

So it's okay, not perfect, but ok and it works .-D
Thansk for helping, the effect looks nice and that's fits for me.
Here the code, if somebody needs it, too:
Code:
//////////////////////////////
// Zustand: Brennen
//////////////////////////////

BMAP* pct_p_fire01	=	"pct_p_fire01.tga";
BMAP* pct_p_fire02	=	"pct_p_fire02.tga";
BMAP* pct_p_fire03	=	"pct_p_fire03.tga";

function p_flammen_out(PARTICLE *p)	// fading out and if entity moves, it leaves the flame behing
{
	p.alpha -= p.skill_c*time_step;
	if (p.alpha <= 30) p.bmap = pct_p_fire02;
	if (p.alpha <= 15) p.bmap = pct_p_fire03;
	if (p.alpha <=  0) p.lifespan = 0;
}
function p_flammen_in(PARTICLE *p)	// fading in and stay at position
{
	p.alpha += p.skill_c*time_step;
	if (p.alpha >= 15) p.bmap = pct_p_fire02;
	if (p.alpha >= 30) p.bmap = pct_p_fire01;
	if (p.alpha >= 50) p.event = p_flammen_out;
	you = p.skill_a;
	if(!you) {p.lifespan = 0; return;}
	vec_for_vertex(p.x, you, p.skill_b);
}

function p_condition_burning(PARTICLE* p)
{
	p.skill_a = p.vel_x;			// pointer auf brennende Entity
	p.skill_b = p.vel_y;			// Nummer des Vertex
	p.skill_c = 8+random(4); 		// Fadefaktor
	set(p, BRIGHT | TRANSLUCENT);
	p.alpha = random(10);
	p.bmap = pct_p_fire03;
	p.size = 16+random(5);
	p.event = p_flammen_in;
}


function eff_test_burning()
{
	VECTOR vel;
	int gesamt_vertices = ent_status(my, 0);
	while(1)
	{
		vel.x = me;
		vel.y = integer(random(gesamt_vertices));
		vel.z = 0;
		effect(p_condition_burning,1,my.x,vel); //pointer and vertex stored in vel
		wait(1);
	}
}



Thanks!!! :-D
© 2024 lite-C Forums