Vector Problem

Posted By: GreenDeveloper

Vector Problem - 11/10/12 12:45

hello everybody;
i have a small probmelem.

i want always do that


but when i turn player angle, its have a small problem





Code:
function particle()
{
	vec_add(par_vec.x, player.x);
	vec_set(par_vec.x, vector(0, 0, 0));
	vec_rotate(par_vec.x, player.pan);
	par_vec.x = player.x - 10 * cos(player.pan);
 	par_vec.y = player.y - 10 * sin(player.pan);
 	par_vec.z = player.z + 10;
 	
	cikarma = 1;	
	while(key_space)
	{
		if(cikarma==1)
		{
			effect(gas_function, 20, par_vec.x, nullvector);
			media_play("fart.wav", NULL, 100);
		}
		wait(1);
	
	}	
}

Posted By: Ch40zzC0d3r

Re: Vector Problem - 11/10/12 12:57

first vec_set, then vec_rotate and then finally vec_add wink
Just do:
Code:
vec_set(par_vec.x, vector(10, 0, 0));
vec_rotate(par_vec.x, player.pan);
vec_add(par_vec.x, player.x);

Posted By: GreenDeveloper

Re: Vector Problem - 11/10/12 13:00

it doesnt work. frown
Posted By: Kartoffel

Re: Vector Problem - 11/10/12 13:08

sorry, but does this make any sense?
Code:
vec_add(par_vec.x, player.x);
vec_set(par_vec.x, vector(0, 0, 0));
vec_rotate(par_vec.x, player.pan);



...and can you please post the particle-function, too?
I think the 'problem' should be in there.

EDIT: or try this (not tested):
Code:
function particle()
{
	VECTOR particle_velocity;
 	
 	var speed = 5; // particle speed - this needs to be adjusted!
 	
	cikarma = 1;	
	while(key_space)
	{
		if(cikarma==1)
		{
			vec_set(particle_velocity, vector(-speed, 0, 0);
			vec_rotate(particle_velocity, player.pan);
			
			effect(gas_function, 20, player.x, particle_velocity);
			media_play("fart.wav", NULL, 100);
		}
		wait(1);
	}	
}

Posted By: GreenDeveloper

Re: Vector Problem - 11/10/12 13:25

Originally Posted By: Kartoffel
sorry, but does this make any sense?
Code:
vec_add(par_vec.x, player.x);
vec_set(par_vec.x, vector(0, 0, 0));
vec_rotate(par_vec.x, player.pan);



...and can you please post the particle-function, too?
I think the 'problem' should be in there.

EDIT: or try this (not tested):
Code:
function particle()
{
	VECTOR particle_velocity;
 	
 	var speed = 5; // particle speed - this needs to be adjusted!
 	
	cikarma = 1;	
	while(key_space)
	{
		if(cikarma==1)
		{
			vec_set(particle_velocity, vector(-speed, 0, 0);
			vec_rotate(particle_velocity, player.pan);
			
			effect(gas_function, 20, player.x, particle_velocity);
			media_play("fart.wav", NULL, 100);
		}
		wait(1);
	}	
}



sorry, but does this make any sense? - unfortunately no.

EDIT: or try this - it gives the same result

...and can you please post the particle-function, too? - here;

Code:
function event_gas(PARTICLE *p)
{
	p.red=5;
	p.blue=5;
	p.green=500;
}

function gas_function(PARTICLE *p)
{
	p.vel_y +=random(50);
	p.vel_x -=random(90);
	p.vel_z +=random(8)+2;
	p.red=206;
	p.blue=22;
	p.green=32;
	p.lifespan=5;
	p.size=random(20) + 5;
	p.bmap=greenparticle;
	p.event=event_gas;
	max_particles=30;
	set(p, MOVE | BRIGHT | TRANSLUCENT);
}

Posted By: Ch40zzC0d3r

Re: Vector Problem - 11/10/12 13:27

-.-
p.vel_y +=random(50);
p.vel_x -=random(90);
p.vel_z +=random(8)+2;

Use my code instead of this + add some randoms
Posted By: Kartoffel

Re: Vector Problem - 11/10/12 14:01

Ch40zzC0d3e is right.
you way of randomizing the particle's velocity is the problem.

It has to be applied before rotating the velocity vector:
Code:
function particle()
{
	VECTOR particle_velocity;
 	
 	var speed = 5; // particle speed - this needs to be adjusted!
 	var r_a = 75; // random angle

	cikarma = 1;	
	while(key_space)
	{
		if(cikarma==1)
		{
			vec_set(particle_velocity, vector(-random(speed), 0, 0); // randomize velocity
			vec_rotate(particle_velocity, vector(player.pan + random(r_a / 2) - r_a, player.tilt + random(r_a / 2) - r_a, 0); // randomize angle
			
			effect(gas_function, 20, player.x, particle_velocity);
			media_play("fart.wav", NULL, 100);
		}
		wait(1);
	}	
}


this should work if you remove the random velocity from your particle function
© 2024 lite-C Forums