Hello guys,
Just started with 3D Gamestudio and got a question about AUM 58, workshop33. In that example you can shoot with a rifle one bullet at a time. But I want to create a rifle who can shoot more bullets at a time randomly (like a sawed-off shotgun). I succeed, but I have a problem. The bullets are coming out randomly, but when the bullets hit each other, the program will remove the bullets.
So what I want is, how can the bullets ignore each other?
This is not the whole code, but just a part off it.
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
{
vec_for_vertex (temp.x, weapon1, 29); // get the coordinates for the bullets' origin
// create the bullet at camera's position and attach it the "move_bullets" function
ent_create (bullet_mdl, temp.x, move_bullets);
ent_create (bullet_mdl, temp.x, move_bullets);
ent_create (bullet_mdl, temp.x, move_bullets);
ent_create (bullet_mdl, temp.x, move_bullets);
ent_create (muzzle_pcx, temp.x, display_muzzle); // create the gun muzzle
snd_play (bullet_wav, 100, 0); // play the bullet sound at a volume of 100
sleep (0.14); // fire 7 bullets per second (0.14 * 7 = 1 second)
}
}
function move_bullets()
{
var bullet_speed; // this var will store the speed of the bullet
my.enable_impact = on; // the bullet is sensitive to impact
my.enable_entity = on; // and to other entities
my.enable_block = on; // as well as to level blocks
my.event = remove_bullets; // when it collides with something, its event function (remove_bullets) will run
my.pan = camera.pan; // the bullet has the same pan
my.tilt = camera.tilt; // and tilt with the camera
bullet_speed.x = 200 * time; // adjust the speed of the bullet here
bullet_speed.y = (-1+random(2)); // the bullet does move sideways
bullet_speed.z = (-2+random(4));
while (my != null) // this loop will run for as long as the bullet exists (it isn't "null")
{
// move the bullet ignoring the passable entities and store the result in distance_covered
c_move (my, bullet_speed, nullvector, ignore_passable);
wait (1);
}
}
function remove_bullets() // this function runs when the bullet collides with something
{
wait (1); // wait a frame to be sure (don't trigger engine warnings)
ent_create (explosion_pcx, my.x, explosion_sprite); // create the explosion sprite
my.passable = on; // the bullets becomes passable and invisible now
my.invisible = on; // so it can't harm anyone anymore
sleep (2); // wait until the explosion_sprite() function is over
ent_remove (my); // and then remove the bullet
}
Last edited by GieskeBon; 04/18/10 15:24.