1 registered members (monarch),
1,259
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Confusion about vel_x
#251512
02/13/09 13:22
02/13/09 13:22
|
Joined: Jan 2009
Posts: 34
DrunkenPirate
OP
Newbie
|
OP
Newbie
Joined: Jan 2009
Posts: 34
|
Hello, I'm trying to create a solid laser line that shoots from the ship to a certain distance via the mouse. Here is my code: function weapon_fire() {
vec_for_vertex (gunLeft, player, 679);
vec_for_vertex (gunRight, player, 737);
if (mouse_left) {
if (laserActive != 1) {
tracer = ent_create("bullet.mdl",nullvector,NULL);
effect (weapon_laser, 1, gunLeft, nullvector);
}
laserActive = 1;
}
}
//Laser weapon
function weapon_laser(PARTICLE* p) {
p.flags |= (BRIGHT | BEAM | TRANSLUCENT);
p.event = laser_fade; //Move to faster function
p.size = 0.3;
p.bmap = laser; //the effect bitmap
}
function laser_fade(PARTICLE* p) {
if (mouse_left == 0) {
p.lifespan = 0;
laserActive = 0;
}else{
p.lifespan = 100;
vec_set(p.x,gunLeft);
vec_set(mouseTemp,vector(mouse_pos.x,mouse_pos.y,200));
vec_for_screen(mouseTemp,camera);
vec_set(temp,mouseTemp);
vec_set(p.vel_x,temp);
vec_set(tracer.x,temp);
}
} The "tracer" object works fine and stays at the mouse position as it should. The particle line does not. It moves when the mouse is moved (as it should) but it does not always shoot at the mouse. (Often times the laser will be shooting below the plane when the mouse is to the left of it, etc) Thank you
|
|
|
Re: Confusion about vel_x
[Re: DrunkenPirate]
#251874
02/15/09 12:02
02/15/09 12:02
|
Joined: Jan 2009
Posts: 34
DrunkenPirate
OP
Newbie
|
OP
Newbie
Joined: Jan 2009
Posts: 34
|
Here is a working script for anyone who needs it: //**********************WEAPON MASTER*********************//
//***
//**************************END***************************//
//************************INCLUDES************************//
//**************************END***************************//
//**************************NOTES*************************//
//***No Notes.
//**************************END***************************//
//**************************TODO**************************//
//***No Todo
//**************************END***************************//
//********************GLOBAL VARIABLES********************//
//***Any global variables go here. This is NOT the place
//***for entities or other such declarations.
VECTOR gunLeft;
VECTOR gunRight;
var laserActive;
VECTOR mouseTemp;
VECTOR laserDir; //Direction the space dust blows
VECTOR pPos;
//**************************END***************************//
//************************ENTITIES************************//
//***All entity declarations go here. (Unless local only!)
ENTITY* bullet;
ENTITY* tracer;
//**************************END***************************//
//************************FUNCTIONS***********************//
//***All function declarations go here.
function weapon_fire(); //Fires the weapons
function weapon_laser(PARTICLE* p); //Fires the laser
function laser_fade(PARTICLE* p); //Turns off the laser
//**************************END***************************//
//********************OTHER DECLARATIONS******************//
//***All other declarations like panels, sprites, etc
//***get thrown in here. Keep them organized in sections!
BMAP* laser = "laser_blue.tga";
//**************************END***************************//
//**********************FUNCTION CODE*********************//
//***All function code goes here. Try to keep this neat and
//***write your functions in groups in seperate files if
//***possible.
//Fires the weapons
function weapon_fire() {
vec_for_vertex (gunLeft, player, 679);
vec_for_vertex (gunRight, player, 737);
if (mouse_left) {
if (laserActive != 1) {
tracer = ent_create("bullet.mdl",nullvector,NULL);
effect (weapon_laser, 1, gunLeft, nullvector);
}
laserActive = 1;
}
}
//Laser weapon
function weapon_laser(PARTICLE* p) {
p.flags |= (BRIGHT | BEAM | TRANSLUCENT);
p.event = laser_fade; //Move to faster function
p.size = 0.6;
p.bmap = laser; //the effect bitmap
}
function laser_fade(PARTICLE* p) {
if (mouse_left == 0) {
p.lifespan = 0;
laserActive = 0;
}else{
p.lifespan = 100;
vec_set(p.x,gunLeft);
vec_set(mouseTemp,vector(mouse_pos.x,mouse_pos.y,2000));
vec_for_screen(mouseTemp,camera);
vec_set(pPos,mouseTemp); //Sets the position to the camera
temp.x = cos(camera.pan); //Computes for pan & tilt
temp.y = sin(camera.pan);
temp.z = 600*cos(camera.tilt);
pPos.x = pPos.x + temp.z*temp.x; //Sets the final positions
pPos.y = pPos.y + temp.z*temp.y;
pPos.z = pPos.z + 600*sin(camera.tilt);
vec_set(laserDir,camera.x); //Sets the vector to camera pos
vec_sub(laserDir,pPos.x); //Subtracts the position of the emitter
//vec_scale(laserDir,0.05); //Scales the vector, so things don't go too fast.
vec_inverse(laserDir);
vec_set(p.vel_x,laserDir);
vec_set(tracer.x,laserDir);
}
}
//**************************END***************************//
|
|
|
|