|
1 registered members (Quad),
1,951
guests, and 6
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Need help with shooting
#337314
08/10/10 06:57
08/10/10 06:57
|
Joined: Apr 2005
Posts: 796 U.S.A. Michigan
exile
OP
User
|
OP
User
Joined: Apr 2005
Posts: 796
U.S.A. Michigan
|
Ok so I am trying to use a c_trace function for shooting instead of making a physical model. I am not too used to using c_trace so I am in need of some help. My bullets dont hit anything for some reason, and I would like for the game to trace from the center of the screen to its hit point. Here is my code so far. function fire_bullets(); // creates the bullets function remove_bullets(); // removes the bullets after they've hit something
function players_weapon { my.Znear = on; fire_rate = .08; projectile_speed = 5000; flash_vertex = 901; weapon1 = my; // I'm weapon1 proc_late(); my.material = mtl_vegetation; my.passable = on; // the weapon model is passable gun_zooming_X = -50; while (player == null) {wait (1);} // wait until the player is created while (1) {
////////////WEAPON POSITIONING//////// vec_set (player1_pos.x, player.x); // store the initial player position // place the weapon 50 quants in front, 18 quants to the right and 20 quants below camera's origin if (dist_ahead != 0 && running == 0 && player.aim == 0) // the player has moved during the last frame? { weapon_height += 35 * time; // then offset weapon_height (30 = weapon waving speed) weapon_sway += 17.5 * time; // then offset weapon_height (30 = weapon waving speed) weapon_offset.z += 0.3 * sin(weapon_height); // (0.3 = weapon waving amplitude) weapon_offset.y += 2 * sin(weapon_sway); // (0.3 = weapon waving amplitude) } if (dist_ahead != 0&& running == 1 && player.aim == 0) // the player has moved during the last frame? { weapon_height += 35 * 1.7 * time; // then offset weapon_height (30 = weapon waving speed) weapon_sway += 17.5 * 1.7* time; // then offset weapon_height (30 = weapon waving speed) weapon_offset.z += 0.3 * sin(weapon_height); // (0.3 = weapon waving amplitude) weapon_offset.y += 4 * sin(weapon_sway); // (0.3 = weapon waving amplitude) } if (dist_ahead != 0 && running == 0 && player.aim == 1) // the player has moved during the last frame? { weapon_height += 17.5 * time; // then offset weapon_height (30 = weapon waving speed) weapon_sway += 8.75 * time; // then offset weapon_height (30 = weapon waving speed) weapon_offset.z += 0.3 * sin(weapon_height); // (0.3 = weapon waving amplitude) weapon_offset.y += 1 * sin(weapon_sway); // (0.3 = weapon waving amplitude) } if (dist_ahead != 0 && running == 1 && player.aim == 1) // the player has moved during the last frame? { weapon_height += 17.5 * 1.7 * time; // then offset weapon_height (30 = weapon waving speed) weapon_sway += 8.75 * 1.7* time; // then offset weapon_height (30 = weapon waving speed) weapon_offset.z += 0.3 * sin(weapon_height); // (0.3 = weapon waving amplitude) weapon_offset.y += 2 * sin(weapon_sway); // (0.3 = weapon waving amplitude) } // rotate weapon_offset according to the camera angles vec_rotate (weapon_offset.x, vector (camera.pan, camera.tilt, 0)); vec_add (weapon_offset.x, camera.x); // add the camera position to weapon_offset vec_set (my.x, weapon_offset.x); // set weapon's coords to weapon_offset my.pan = camera.pan; // use the same camera angles for the weapon my.tilt = camera.tilt; vec_set (player2_pos.x, player.x); // store the new player coordinates after 1 frame ////////WEAPON ZOOMING/AIMING///////////// if(mouse_right == 0&& weapon_positionX<=-50) // WHEN IM NOT HOLDING DOWN "AIM" { vec_set (weapon_offset.x, vector (50, -50, hip_height)); // Gun position (Out/In,L/R,U/D) my.z-=6; } if(mouse_right == 1 && weapon_positionX<0) //WHEN I AM HOLDING DOWN "AIM", MOVE THE WEAPON TO THE POSITION { weapon_positionY +=aim_speed/10*time; weapon_positionX +=aim_speed*time; vec_set (weapon_offset.x, vector (50, weapon_positionX, weapon_positionY)); // Gun position (Out/In,L/R,U/D) } if(mouse_right == 1 && weapon_positionX>=0) //MAKE SURE THE WEAPON DOESNT GO PAST THE AIM POINT { vec_set (weapon_offset.x, vector (50, 0, aim_height)); // Gun position (Out/In,L/R,U/D) } if(mouse_right == 0 && weapon_positionX>-50) //WHEN IM NOT HOLDING DOWN "AIM", BUT THE WEAPON ISNT AT THE HIP POINT, RETURN THE WEAPON TO THE HIP { weapon_positionY -=aim_speed/10*time; weapon_positionX -=aim_speed*time; vec_set (weapon_offset.x, vector (50, weapon_positionX, weapon_positionY)); // Gun position (Out/In,L/R,U/D) } wait (1); } }
on_mouse_left = fire_bullets; // call function fire_bullets() when the left mouse button is pressed
function fire_bullets() { proc_kill(4); // don't allow more than 1 copy of this function to run while (mouse_left == on) // this loop runs for as long as the left mouse button is pressed { recoil_amt = .2; mouse_tilt += recoil_amt; //vec_for_vertex (temp.x, weapon1, flash_vertex); // get the coordinates for the bullets' origin vec_set(b_end.x, vector(2000, 25 - random(50), 25 - random(50))); // and it might miss the target from time to time due to the random values vec_rotate(b_end.x, camera.pan); vec_add(b_end.x, camera.x); c_trace(camera.x, b_end.x, IGNORE_ME | IGNORE_PASSABLE | ACTIVATE_SHOOT); // trace 2,000 quants in front of the player flash = ent_create("flasher.mdl",temp.x,muzzle_flash); // create the gun muzzle if (!you) { remove_bullets(); } snd_stop(gun_sound); gun_sound = ent_playsound( weapon1, shot_snd, 1000 ); snd_tune(gun_sound,0,tuner,0); sleep (fire_rate); // fire 7 bullets per second (0.14 * 7 = 1 second) } }
function remove_bullets() // this function runs when the bullet collides with something { if(event_type == EVENT_IMPACT) { wait (1); // wait a frame to be sure (don't trigger engine warnings) //vec_rotate( my.x, normal ); ent_create("impact.mdl",b_end.x,imp_effect); effect(smokespezial,max(1,smokeAnzahlPartikel*time),b_end.x,nullvector); // make smoke particles effect(sparkspezial,20,b_end.x,nullvector); sleep (2); ent_remove (my); // and then remove the bullet }
Last edited by exile; 08/10/10 06:59.
|
|
|
Re: Need help with shooting
[Re: exile]
#337472
08/11/10 04:52
08/11/10 04:52
|
Joined: Apr 2005
Posts: 796 U.S.A. Michigan
exile
OP
User
|
OP
User
Joined: Apr 2005
Posts: 796
U.S.A. Michigan
|
Ok, so I got it to "semi" work. It's still not working the way I need it to though. Whats wrong???
function fire_bullets { // the gun has a firing range of 2,000 quants vec_set(b_end.x, vector(2000, 0, 0)); vec_rotate(b_end.x, camera.pan); vec_add(b_end.x, camera.x); if( !you ) { // hit one of the walls? wait (1); // wait a frame to be sure (don't trigger engine warnings) //vec_rotate( my.x, normal ); ent_create("impact.mdl",b_end.x,imp_effect); effect(smokespezial,max(1,smokeAnzahlPartikel*time),b_end.x,nullvector); // make smoke particles effect(sparkspezial,20,b_end.x,nullvector); } } return; }
|
|
|
Re: Need help with shooting
[Re: exile]
#337475
08/11/10 05:42
08/11/10 05:42
|
Joined: Apr 2005
Posts: 796 U.S.A. Michigan
exile
OP
User
|
OP
User
Joined: Apr 2005
Posts: 796
U.S.A. Michigan
|
NVM guys, I fixed it.... I forgot to add a "trace_hit" condition. Now I have a new problem  For some reason the hit effects still occour even when the trace isnt hitting anything. What did I do wrong???
Last edited by exile; 08/11/10 06:19.
|
|
|
Re: Need help with shooting
[Re: exile]
#337547
08/11/10 17:07
08/11/10 17:07
|
Joined: Apr 2006
Posts: 159 Latvija
Arrovs
Member
|
Member
Joined: Apr 2006
Posts: 159
Latvija
|
How you an know if you arent hitting anything. Possible you hit walls? You better should give some skill which says that trace is bullet. And to other which need be hurten use event which triggers c_trace: enable_shoot. So it will get hurt.
If you think you get collision effect if nothing has hitn, then possible you forget to disable creator from tracing hitting - ignore_me.
Possible that !=you uses parent pointer which create bullets.
Give more exact code. And i will give more exact answer.
Arrovs once will publish game
|
|
|
Re: Need help with shooting
[Re: Arrovs]
#337622
08/12/10 07:33
08/12/10 07:33
|
Joined: Apr 2005
Posts: 796 U.S.A. Michigan
exile
OP
User
|
OP
User
Joined: Apr 2005
Posts: 796
U.S.A. Michigan
|
Thank you for your offer. However I literally just solvd all of my problems.
Last edited by exile; 08/12/10 20:37.
|
|
|
Re: Need help with shooting
[Re: Pappenheimer]
#340797
09/07/10 17:30
09/07/10 17:30
|
Joined: Apr 2006
Posts: 159 Latvija
Arrovs
Member
|
Member
Joined: Apr 2006
Posts: 159
Latvija
|
Hard hard - too much possibilities. And why you have so much while's. Better one while with some ifs. And frame rate shouldnt make difference because you use time_step.
Arrovs once will publish game
|
|
|
|