Gamestudio Links
Zorro Links
Newest Posts
How to select between IB accounts by script?
by AndrewAMD. 06/13/26 15:44
Zorro tutorial ideas?
by AndrewAMD. 06/13/26 15:01
Zorro 3.01 recoded MMI function issue
by 11honza11. 06/13/26 11:40
Max Number of Strategies in /Strategy folder
by Martin_HH. 06/12/26 08:50
Stooq now requires an API key
by AndrewAMD. 06/11/26 17:55
Z9 getting Error 058
by k_ivan. 06/10/26 14:38
ZorroGPT
by TipmyPip. 06/10/26 13:07
Z12 live performance
by alx. 06/09/26 20:42
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
1 registered members (Quad), 1,951 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Student_64151, Koti, curry, DeepxKalsi, Samed
19219 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
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 Offline OP
User
exile  Offline 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.

Click to reveal..

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 Offline OP
User
exile  Offline 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 Offline OP
User
exile  Offline 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 frown

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 Offline
Member
Arrovs  Offline
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 Offline OP
User
exile  Offline 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: exile] #340000
08/30/10 18:35
08/30/10 18:35
Joined: Apr 2005
Posts: 796
U.S.A. Michigan
exile Offline OP
User
exile  Offline OP
User

Joined: Apr 2005
Posts: 796
U.S.A. Michigan
Ok not really a problem but I need some help on improving this code. This code causes the weapon entity to "recoil" when firing. It works fine for what it does but it could be better... MUCH better. For example, the code is VERY frame rate dependent. So if the fps drops below 60-ish, the weapon wont stop at its defined stopping point and will fly back further (sometimes almost a good 3-ft in game measurements). I would preferably like to use c_move to perform this function but I only know how to use c_move for making bullets and such. Anybody have any ideas on how I can improve my code???

while(weapon.positionZ > weapon.max_recoil_dist)
{
weapon.positionZ -=weapon.fire_rate*100*time_step;
wait(1);
}
while(weapon.positionZ < weapon.defZ)
{
weapon.positionZ +=weapon.fire_rate*30*time_step;
wait(1);
}
if(weapon.positionZ > weapon.defZ)
{
weapon.positionZ = weapon.defZ;
}
if(weapon.positionZ < weapon.max_recoil_dist)
{
weapon.positionZ = weapon.max_recoil_dist;
}

Also, I have a code that moves an entity along a pre defined path. Again, it works fine but could be better. Essentially, I need the entity to move along a path that is calculated from the entity's starting x and y positions to its ending x,y positions. The entity should gradually increase/decrease its x/y movement based on this result. I tried to use some basic algebra to get this result but again, it wont work. Any ideas???

Re: Need help with shooting [Re: exile] #340137
09/01/10 05:03
09/01/10 05:03
Joined: Apr 2005
Posts: 796
U.S.A. Michigan
exile Offline OP
User
exile  Offline OP
User

Joined: Apr 2005
Posts: 796
U.S.A. Michigan
"Help, would you kindly?...." Hahaha

Re: Need help with shooting [Re: exile] #340191
09/01/10 19:19
09/01/10 19:19
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
I would use an animation for the recoil.

As for the path, make a different thread with a better fitting headline.

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 Offline
Member
Arrovs  Offline
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

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1