• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

physic particles

G

graviax

Guest
I made a blood particle coming out of the flying corpses in my game but, I made it using only object.

problem is it can be very laggy
Code:
if(!place_meeting(x,y+1,obj_wall))
  {
  if(vsp < 30)vsp += 0.1;
  }
  //Horizontal Collision
  if (place_meeting(x+hsp,y,obj_wall))
  {
  while(!place_meeting(x+sign(hsp),y,obj_wall))
  {
  x += sign(hsp);
  }
  hsp = 0;
  }
  x += hsp;

  //Vertical Collision
  if (place_meeting(x,y+vsp,obj_wall))
  {
  while(!place_meeting(x,y+sign(vsp),obj_wall))
  {
  y += sign(vsp);
  }
  vsp = 0;
  }
  y += vsp;
So i tried to make a particle emitter but, I don't know how to make the blood stay on the ground.
Is there a way to make particle "physic"?
 

BLang

Member
With the built-in particle system, no. It used to be possible in older versions of GM, but they have been simplified a lot since then to allow a bigger amount of particles on screen with less of a performance hit.

There's also soft body particles. Those use the box2d physics.

And the third option is, of course, doing it the way you did it, but optimizing, optimizing, optimizing.
 
G

graviax

Guest
With the built-in particle system, no. It used to be possible in older versions of GM, but they have been simplified a lot since then to allow a bigger amount of particles on screen with less of a performance hit.

There's also soft body particles. Those use the box2d physics.

And the third option is, of course, doing it the way you did it, but optimizing, optimizing, optimizing.
Thx for the reply, but now there's another big question in my mind, how do I optimize this?
I vaguely know what can make a computer slow down but, I don't have any clue in GML.
 

BLang

Member
Well, right now, I'm assuming you're doing all the blood particles as separate instances, but creating an instance can actually be a pretty significant performance hit. A common workaround is to make all the different blood particles a single object that uses a 2D array or a grid or something similar to store the positions of all the particles. Then, every step, it iterates through the whole grid to update their positions, and then, in the end, in the draw event, you iterate through the grid again and draw all the blood particles in the correct positions.
 

FrostyCat

Redemption Seeker
First of all, there is no need for this level of precision with blood particles. Replacing the repeated calls to place_meeting() with just a single one checking the current position would save you dozens of collision checking calls every step on every particle.

Secondly, the splatters should not remain in instance form after it lands, since it would still be running collision checks and its own drawing code every step. You can use surfaces to consolidate the drawing into one place, as demonstrated here.
 
G

graviax

Guest
So I basicaly take a "screenshot" of the fixed blood particle and then remove it (the non-moving blood particle).
 
Top