Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (AndrewAMD, Baklazhan, Ayumi, Hanky27), 1,387 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
bullets and collisions #318087
04/04/10 22:09
04/04/10 22:09
Joined: Jul 2008
Posts: 128
Ukraine
BastovBros Offline OP
Member
BastovBros  Offline OP
Member

Joined: Jul 2008
Posts: 128
Ukraine
Hi all, I have a problem... I am using a code of a bullet that should hit the target (a guy in my case). The bullet moves with the speed +100*time_step, but I cannot manage to code the collision properly. When the guy stands in the way of the flying bullet, no blood sprite appears. It appears only when the guy is moving along the bullet trail. It seems that the collision works only when the guy is in certain coordinates, say at 0, then 100, then 200, 300 and so on, since the speed of the bullet is +100. And if he is standing say at 120 or 350, no effect occurs. I saw how people just make the trace from the gun and calculate the collision right away at the moment of shooting the bullet, so the collision occurs instantaneously. However, I want it to occur exactly when the bullet hits the guy, even though the bullet is moving extremely fast. Any ideas how to do this? As I noticed the code which I am suing was mostly used for slowly moving bullets...
Code:
function fire_bullets() // includes the code that animates the weapon as well
{
       VECTOR temp;
       VECTOR temp1;
       proc_kill(4); // don't allow more than 1 copy of this function to run
       while (mouse_left) // this loop runs for as long as the left mouse button is pressed
       {
               vec_set(temp.x,gun_fire_ent.x); // get the coordinates for the bullets' origin
               vec_set(temp1.x, gun_fire2_ent.x);
                // create the bullet at camera's position and attach it the "move_bullets" function
               ent_create ("bullet.mdl", temp1.x, move_bullets);
               ent_create ("gun_fire.tga", temp1.x, display_muzzle);
               ent_create ("bullet.mdl", temp.x, move_bullets);
               ent_create ("gun_fire.tga", temp.x, display_muzzle); // create the gun muzzle
              // snd_play (bullet_wav, 100, 0); // play the bullet sound at a volume of 100
               wait (-0.2); // number of bullets, 6 bullets per second, if 0.1 - 10 bullets per second
       }
}

function p_alphafade(PARTICLE *p)
{
    p.alpha -= 1*time_step;
    if (p.alpha <= 0) p.lifespan = 0;
}

function p_trace(PARTICLE *p)
{
   set(p, BRIGHT|TRANSLUCENT|STREAK);
   p.alpha = 10;
   p.size = 10;
   //p.skill_a = 1; // fade factor
   p.event = p_alphafade;
}
ENTITY* bullet_ent;
function move_bullets()
{
		 VECTOR last_pos;
       VECTOR bullet_speed; // stores the speed of the bullet
       bullet_ent = me;
       my.scale_x = 0.2;
       my.scale_y = my.scale_x;
       my.scale_z = my.scale_x;
       my.skill30 = 1; // I'm a bullet
       my.emask |= (ENABLE_IMPACT | ENABLE_ENTITY | ENABLE_BLOCK);
       set(me,BRIGHT|LIGHT); 
       set(my,PASSABLE);
       my.event = remove_bullets; // when it collides with something, its event function (remove_bullets) will run
       my.pan = player.pan; // the bullet has the same pan
       my.tilt = player.tilt; // and tilt with the camera
       bullet_speed.x = 100 * time_step; // adjust the speed of the bullet here
       bullet_speed.y = 0; // the bullet doesn't move sideways
       bullet_speed.z = 0; // then don't allow the gravity to have its ways with the bullet
       while (my) // 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
               vec_set(last_pos.x,my.x);
               c_move (my, bullet_speed, nullvector, IGNORE_PASSABLE);
               effect(p_trace,1,my.x,vec_sub(last_pos.x,my.x));
               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 ("gun_fire.tga", my.x, explosion_sprite); // create the explosion sprite
       set (my, INVISIBLE | PASSABLE);
       wait (-2); // wait until the explosion_sprite() function is over
       ent_remove (my); // and then remove the bullet
}
function display_muzzle()
{
       set (my, PASSABLE | LIGHT);
       my.roll = 0.01;
       my.ambient = 100; // and this line makes it even brighter
       my.pan = player.pan; // has the same pan and tilt
       my.tilt = player.tilt; // with the weapon
       my.roll = random(360); // and a random roll angle (looks nicer)
       my.scale_x = 0.05; // we scale it down
       my.scale_y = my.scale_x; // on all the axis
       my.scale_z = my.scale_z; // this would only be needed for a 3D (model-based) muzzle
       player.ambient = 100; // highlight the weapon (makes it look more realistic)
       wait (2); // show the muzzle sprite for 2 frames
       player.ambient = 0; // restore the normal weapon ambient value
       ent_remove (my); // and then remove it
}
function explosion_sprite()
{
       set (my, PASSABLE | BRIGHT | TRANSLUCENT);
       my.scale_x = 0.15; // we scale it down to 0.15
       my.scale_y = my.scale_x; // on both axis
       my.ambient = 100; // and we give it an ambient of 100
       my.roll = random(360); // we set a random roll angle
       my.alpha = 100; // but we set it to be completely opaque for now
    //   while (my.frame < 5) // go through all the animation frames
    //   {
    //           my.frame += 2 * time_step; // animation speed
    //           wait (1);
    //   }
       while (my.alpha > 0) // now fade the last frame quickly
       {
               my.alpha -= 50 * time_step; // 50 = fading speed
               wait (1);
       }
       ent_remove (my);
}


here is also a video to show you what I mean. As you can see the guy stands in the way of the bullets, but no collision occurs. When the guy is moving, some collisions do occur, but randomly, not always (you can see an explosion sprite, I don't have blood sprite yet). Furthermore, the event sprite (explosion sprite) appears in the next frame, when the bullet is already 100 quants ahead and not at the guy....
http://www.youtube.com/watch?v=pLileH6LBBM
thank you for any help


a generator of dull questions smile
Re: bullets and collisions [Re: BastovBros] #318089
04/04/10 22:21
04/04/10 22:21
Joined: Sep 2009
Posts: 496
P
Progger Offline
Senior Member
Progger  Offline
Senior Member
P

Joined: Sep 2009
Posts: 496
u forgot IGNORE_YOU in c_move
i dont know if it is important but maybe its helpful
WFG Progger


asking is the best Way to get help laugh laugh laugh
Re: bullets and collisions [Re: Progger] #318104
04/05/10 10:50
04/05/10 10:50
Joined: Dec 2008
Posts: 605
47°19'02.40" N 8°32'54.67" E...
hopfel Offline
User
hopfel  Offline
User

Joined: Dec 2008
Posts: 605
47°19'02.40" N 8°32'54.67" E...
I don't see an other way to fix this problem excepting using c_trace from the gun. But you can try to use the distance from the gun to the target to calculate the time until the bullet hits the target.

1. shoot
2. calculate distance
3. wait (play with the calculated distance variable)
4. check, if the gun eyes the target
5. animate the blood at the x and y coordinates from "target"


Hilf mir, dir zu helfen!
Re: bullets and collisions [Re: hopfel] #318222
04/06/10 07:07
04/06/10 07:07
Joined: Aug 2008
Posts: 482
B
bart_the_13th Offline
Senior Member
bart_the_13th  Offline
Senior Member
B

Joined: Aug 2008
Posts: 482
Try this:
1. calculate the bullet next_position
2. c_trace from current position to next position
3. if not hit move bullet to next position
4. if hit move bullet position to hit position(or what ever you want to do)

or

1. copy current position to last_position vector
2. move bullet
3. c_trace from last_position to current position
4. if not hit move bullet to next position
5. if hit move bullet position to hit position(or what ever you want to do)


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

Gamestudio download | chip programmers | 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