Can you help me with this function?

Posted By: Vyse220

Can you help me with this function? - 03/08/09 12:12

The idea is that when an enemy is killed, a flow of particles moves from the destroyed enemy to the player.
Code:
function move_power(){
	my.passable = on;
	my.size = 0.1;
	var c;
	while(vec_dist(me, player) > 10 && my. x > -200){
		ent_move(vector(-10, 0, 0), vector(-5, 0, 0));
		c = random(360);
		effect (minpart, 10, my.x, nullvector);
		wait(1);
		if(my.z < player.z){
			my.z += 5;
		}
		if(my.y > player.y){
			my.pan += 4;
			my.y -= 5;
		}
		else{
			my.pan -= 4;
			my.y += 5;
		}
	}
	ent_create("glow.tga", vector(player.x, player.y, player.z - 80), explosion_ring1);
	ent_remove(me);
}

I've done it with this code, but it isn't good, the movement is not good.
Can you help me to do something better? I've used particles, but i would like to use the "beam effect".
This is a demostration of my work as you can see, the movemen't isn't "smooth".
Posted By: DiegoFloor

Re: Can you help me with this function? - 03/09/09 08:50

Hello!

First of all, I still don't know anything about particles, so if I say something that doesn't make any sense jsut ognore laugh But aesthetically maybe I can help.

My first impression was that the particles were in a perfect line and all of the same size. A few patterns I can think of:
-Make the first one bigger and the following gradually smaller (with random oscilations);
-Also, change the opacity so that the last ones on the line are barely visible (making the opacity oscilate a little could work too)

Also, you can try to make additional layers of particles to achieve some sort of glow effect. Or even sparkles leaving the main trail in random directions.

I'm about to start playing around with particles too.. isn't there some sort of particle editor? it's hard to come up with something visually appealing only with coding.
Posted By: Vyse220

Re: Can you help me with this function? - 03/09/09 12:56

Originally Posted By: DiegoFloor
Hello!

First of all, I still don't know anything about particles, so if I say something that doesn't make any sense jsut ognore laugh But aesthetically maybe I can help.

My first impression was that the particles were in a perfect line and all of the same size. A few patterns I can think of:
-Make the first one bigger and the following gradually smaller (with random oscilations);
-Also, change the opacity so that the last ones on the line are barely visible (making the opacity oscilate a little could work too)

Also, you can try to make additional layers of particles to achieve some sort of glow effect. Or even sparkles leaving the main trail in random directions.

I'm about to start playing around with particles too.. isn't there some sort of particle editor? it's hard to come up with something visually appealing only with coding.


I remember a tool that was in the site, something that show in real time the particles and instead put the velocity, the size and other proprieties.
It can be really usefull.

However my problem is't the particle, but the movement of them, thx for the help.
Posted By: vertex

Re: Can you help me with this function? - 03/09/09 14:20

I know this might not help for a variable/dynamic particle method-- but nonetheless: a great tool for particles for Gamestudio:

http://www.easyparticle.com/

developed by:
Timo Stark, Martin Teichmann


Posted By: dracula

Re: Can you help me with this function? - 03/09/09 15:06

Does Easy Particle only produce C- Script code and not Lite-C ?

The interface looks superb

thanks
Posted By: vertex

Re: Can you help me with this function? - 03/09/09 17:12

This is a remake of Easy Particle done by Tobias and is referenced in the Lite-C contribution area.

It outputs Lite-C.

Tobias' lite-C conversion of Easy Particle
Posted By: Vyse220

Re: Can you help me with this function? - 03/11/09 15:58

I still can't understeand how I can do this sorta of parabolic movement, someone have an idea? can help me?
Posted By: DiegoFloor

Re: Can you help me with this function? - 03/11/09 20:29

Ooh! You want a better trajectory? is that it?

You can achieve "some sort" of parabolic movement simply by making the velocity vector of the particle always pointing at the player. To give it a little more movement, make the velocity vector's amplitude increase gradually, this way the particle will "fall" a little (to the bottom of the screen) before gaining velocity towards the player. (This is known as the predator-prey model)

Another possibility is to make the player something like a sun and the particle a tiny planet. Of course, you're not using the physics system, so you have to code this interaction yourself. But it's not difficult! Basically, you have to make tiny incremente to the particle's velocity towards the player per time unit (it's slightly different from the first approach). To make this solution more like a sun-planet system, make the increment increase with the distance to the player.

I don't know squat about coding particles, but at least I know a little about physics laugh yay


edit: ...make the increment decrease with the distance... Because we want the particle to get more accelerated as it gets closer to the player.
Posted By: Vyse220

Re: Can you help me with this function? - 03/12/09 20:55

Quote:
You can achieve "some sort" of parabolic movement simply by making the velocity vector of the particle always pointing at the player. To give it a little more movement, make the velocity vector's amplitude increase gradually, this way the particle will "fall" a little (to the bottom of the screen) before gaining velocity towards the player. (This is known as the predator-prey model)

Thx for it, but can you explane me how to set a vector from the destroyed enemy to the player and move one object towards it please?
Posted By: DiegoFloor

Re: Can you help me with this function? - 03/12/09 21:32

You 'ent_removed' the enemy, of course. But do you need the enemy position for that? I thought that trail of particles was some sort of new entity, and we had to use the head of it as the position. You're supposed to work with the particle's velocity.
Posted By: Vyse220

Re: Can you help me with this function? - 03/13/09 19:24

yes, actually the function create an object that left a particle trail, so, for example, i should do something like:
my.x = vo * cos(c) * t;
the problem is that it doesn't reach the player.
Posted By: DiegoFloor

Re: Can you help me with this function? - 03/14/09 07:20

Try something like this:

vec_diff(velocity, player.x, me.x); // Now we have a vector from the particle to the player (right now it doesn't mean anything)
vec_normalize(velocity, magnitude); //whatever the size..
vec_add(velocity, me.x); //now the velocity is in the correct place

After we have the velocity vector, we just use it to change the position as we normally would.

me.x += velocity.x * time_step;
me.y += velocity.y * time_step;

This has to be done every frame.

If you want to do with c_move, you have the option of using 'relative vector', and we don't need the vec_add.

Now, if the particle isn't reaching the player, just increase the magnitude of the velocity vector. Add something like a magnitude += 0.1; (have to experiment with some values)
Posted By: DiegoFloor

Re: Can you help me with this function? - 03/14/09 07:24

This is a working code

Code:
#include <acknex.h>
#include <default.c>

ENTITY* ball;
ENTITY* ball2;


action action_ball()
{
	VECTOR velocity;
	var magnitude = 0.1;
	while(!key_space){wait(1);} //press space to start the chase!
	while(1)
	{
		vec_diff(velocity, ball2.x, me.x); 
		vec_normalize(velocity, magnitude);
		magnitude +=0.003;
		c_move(me, nullvector, velocity, IGNORE_MAPS);
		wait(1);
	}
}

action action_ball2()
{
	while(!key_space){wait(1);}
	while(1)
	{
		c_move(me,nullvector, vector(10*time_step,0,0),NULL);
		wait(1);
	}
}

function main()
{
	mouse_mode = 1;
	level_load("some_map.wmb");
	wait (2); 
	
 	
 	ball2 = ent_create ("ball.mdl", vector(-100, -200, 0), action_ball2);
 	ball = ent_create ("ball.mdl", vector(100, 100, 0), action_ball);
 	
 	
 	vec_set(camera.x, vector(0,0,600)); 	
 	while(1)
 	{
 		camera.pan -= mouse_force.x * 12 * time_step;
		camera.tilt += mouse_force.y * 8 * time_step;
		wait(1);
 	}	
}

Posted By: Vyse220

Re: Can you help me with this function? - 03/15/09 11:04

thx! you helped me a lot!
the only problem is that the player sometimes get hit by this things and my.passable = on; is set Oo
However, thx laugh
Posted By: EvilSOB

Re: Can you help me with this function? - 03/15/09 14:33

add the IGNORE_PASSABLE flag to the c_move calls in the actions of the entities that are hitting him.
EG: c_move(me, nullvector, velocity, IGNORE_MAPS|IGNORE_PASSABLE);
© 2024 lite-C Forums