Vec_for_vertex --- problem with temp.x

Posted By: June

Vec_for_vertex --- problem with temp.x - 02/28/18 05:23

Hello,

I'm adding a muzzle flash model to be created when the gun fires. The flash is supposed to come from a specified vertex which I believe is in the code correctly.

Here is the code:

vec_for_vertex (temp.x, plyr_machinegun, 32);

ent_create (mflash_mgun_mdl, temp.x, muzzle_flash);


However, when I run the engine, there is this error message:

'temp' undeclared identifier
< vec_for_vertex (temp.x, plyr_machinegun, 32); >


Can anyone see what is causing the problem?
Posted By: 20BN

Re: Vec_for_vertex --- problem with temp.x - 02/28/18 05:41

replace temp to other.

VECTOR* vec_your_set;
or in void
VECTOR vec_your_set;
Posted By: June

Re: Vec_for_vertex --- problem with temp.x - 02/28/18 17:15

A simple solution, thank you 20BN.

I believe temp.x worked in .wdl code but not in lite-c.
Posted By: Superku

Re: Vec_for_vertex --- problem with temp.x - 02/28/18 18:56

The reason is that temp was a predefined VECTOR in wdl but not in lite-C.
Just write
VECTOR temp; // don't make it a pointer (VECTOR*)
at the start of your script, in your function or directly before the commands and it will work.

Btw. the ".x" suffix is superfluous on VECTORs.
Posted By: June

Re: Vec_for_vertex --- problem with temp.x - 03/01/18 05:43

Thank you for the tips Superku.

Do you know if its possible to use vec_for_vertex on a ent_createlayer entity?

I've been trying for many hours to figure it out.

Basically the first person weapon is created at the start of the game using ent_createlayer.

When the gun is firing the intention is to create a muzzle flash at the vertex # of the tip of the gun. For some reason it is not appearing when the gun fires (bullets are surely coming out though).

The code in the gun firing function:

VECTOR mgun_tip;

vec_for_vertex(mgun_tip, plyr_machinegun, 32);

ent_create (mgun_flash_mdl, mgun_tip, muzzle_flash);

function muzzle_flash()
{
set (my, PASSABLE);
set (my, TRANSLUCENT);
my.ambient = 100;
my.roll = random(360);
my.scale_x = 5.4;
my.scale_y = my.scale_x;
wait (-0.25);
ent_remove (my);
}
Posted By: June

Re: Vec_for_vertex --- problem with temp.x - 03/01/18 08:54

Something I can't seem to figure out from the manual:

Can you use vec_for_vertex on a view entity?
Posted By: Superku

Re: Vec_for_vertex --- problem with temp.x - 03/01/18 09:35

Well the gun is in the camera's own coordinate system and vec_for_vertex would probably return the wrong result either way.
Just find it our yourself what it returns:
- Have the camera at 0-pos and 0-pan. Have your gun at 0-(view-)pos as well. Call vec_for_vertex on your gun and note the result (compare with MED).
- Put the gun at the right position and repeat.
- Moving and rotating the camera should return the same result.
- If so, use vec_rotate(temp,camera.pan) and vec_add(temp,camera.x) to get the world position.
Posted By: June

Re: Vec_for_vertex --- problem with temp.x - 03/01/18 17:36

I see, the vector needs to be converted to a world position. I will play around with it, thank you Superku.
Posted By: June

Re: Vec_for_vertex --- problem with temp.x - 03/02/18 17:18

Your advice worked perfectly.
Posted By: Superku

Re: Vec_for_vertex --- problem with temp.x - 03/02/18 17:39

Very well.
© 2024 lite-C Forums