Hello Guest

Author Topic: Recommended method for simple particle effects?  (Read 20868 times)

fsadeq

  • 2D Toolkit
  • Sr. Member
  • *
  • Posts: 353
    • View Profile
Recommended method for simple particle effects?
« on: August 14, 2012, 08:52:25 pm »
I am in the process of figuring out what is the best way to achieve "rain" effect or any other particles. Should I use 2D Toolkit for something like this, or am I better off using Unity's particle system? I'm trying for the most efficient method for mobile devices. I'm guessing I could have a sprite sheet with some particle textures, but not entirely sure what the best way to animate them would be.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Recommended method for simple particle effects?
« Reply #1 on: August 15, 2012, 12:01:28 am »
Well, I have some code somewhere for a tk2d based particle system. Its reasonably fast, but doesn't support animations (by that I mean no sprite animations, but the sprites do move). I was going to clean that up at some point, but it looks like I don't think I'll get a chance to do that. If you want I can describe the system. It really isn't that complicated to implement.

fsadeq

  • 2D Toolkit
  • Sr. Member
  • *
  • Posts: 353
    • View Profile
Re: Recommended method for simple particle effects?
« Reply #2 on: August 15, 2012, 02:11:50 am »
Sounds like it could be useful, considering I don't need anything really complicated. I'd love to hear how to achieve it.

39thstreet

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 77
    • View Profile
Re: Recommended method for simple particle effects?
« Reply #3 on: August 15, 2012, 02:38:49 pm »
I haven't really had an issue with Shuriken for most of the effects I've wanted to do.   I just make the emitter a really flat box and I get pretty good control.    About the only thing I couldn't do I really want to was use a 2d object as a mesh emitter (that is, have an effect appear over the visible surface of a sprite).

Is there a reason 2dtk would need it's own system?  Some reason to avoid Shuriken?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Recommended method for simple particle effects?
« Reply #4 on: August 15, 2012, 07:38:11 pm »
When I rolled my own, shuriken didn't exist. Anyway, shuriken still doesn't support a subuv region (and rotated regions) does it, which means you can't use sprites from a 2d Toolkit spritesheet. That was the main reason really.

Also, mine supported rewind at runtime (i.e. the sprites derive position from t every frame, rather than euler integrating) which I used for a prototype but never got further than that.

I'll write down some notes later when I get a chance.

fsadeq

  • 2D Toolkit
  • Sr. Member
  • *
  • Posts: 353
    • View Profile
Re: Recommended method for simple particle effects?
« Reply #5 on: August 18, 2012, 12:21:04 am »
When you say the system didn't support animated sprites, could it still select different sprites from an atlas for each particle?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Recommended method for simple particle effects?
« Reply #6 on: August 18, 2012, 10:11:53 am »
Yes, each particle had its own unique sprite. The only controls I had on it was velocity, acceleration, size & start and end color.

There was a downside to this though - all the particles were drawn in one draw call - meaning you couldn't have some particles appear in different z depths and occluded differently. Well they could, but they wouldn't be occluded correctly by sprites at different depths...

Tochas

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Recommended method for simple particle effects?
« Reply #7 on: December 11, 2012, 11:16:21 pm »
Any thoughts how to implement something like the particle system to build things like 2D bullets & 2D explosions?
with collision events and all that stuff

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Recommended method for simple particle effects?
« Reply #8 on: December 12, 2012, 07:58:19 am »
Those are two completely different class of effects aren't they? Bullets would want to collide with the world, and are high frequency, whereas explosions are likely to be lower frequency & might not need to collide...

The approach for both would really depend on how many you have - for example if you didn't have a crazy number of bullets then simple sprites would do the job. If you have LOADS of them (eg. bullet hell shooter), then you'd probably need to write a custom system for that.

I could probably make some more specific suggestions, but I'll need to have a lot more details...

Tochas

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Recommended method for simple particle effects?
« Reply #9 on: December 12, 2012, 05:01:46 pm »
Well, I plan to have up to 200 bullets for a given time. will depend on the number of on-screen enemies
and trails for a few bullets like rockets, lasers and such.
also plan to have dynamic explosions, fire +  smoke +  debri with a growing sphere collider for the splash damage.

[side note]
what would you suggest to propell bullets, use iTween or add a rigid body component and apply some force?
[end of side note]

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Recommended method for simple particle effects?
« Reply #10 on: December 13, 2012, 01:19:53 am »
200 bullets at a time might be a bit expensive to use normal GameObjects with (I'm assuming you're targetting mobile).

I suggest writing a system to do this, and bypass Physx completely. If you have fast moving projectiles, physx is likely to miss them. Much easier to parametrically evaluate the positions based on a function, and then perform collision detection with this. You're not gonna have too many visible enemies / players right? Then just a brute force eval with sphere colliders on each should do the job, and will be fast.

Don't bother with iTween or any other tweening system for this, I think going custom with this will give you the best results, and with not much more work really.

Tochas

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Recommended method for simple particle effects?
« Reply #11 on: December 13, 2012, 01:30:53 am »
Yes we are targetting for mobile devices.

The bullets doesnt move at a high-ish speed as we want to give the player a small chance to dodge them
On our previous project we used up to 25 characters at a time, we might want to stretch that number up a little further. the final number will be set after playtesting the prototype based on dificulty.

Could you elaborate on the custom system idea?, as I have no clue where to start if not using GameObjects with tk2dSprite scripts attached.


unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Recommended method for simple particle effects?
« Reply #12 on: December 13, 2012, 05:15:55 am »
I suggest building it in such a way that is super-convenient to start with, but will be easy enough to switch to a fully custom solution should the need arise.

Something like this:

// This wil create a GameObject with a sprite (i.e. the projectile sprite)
ProjectileManager.CreateProjectile( ProjectileType.RedFireball, lifeTime, projectilePos, projectileRotation, ProjectileMotionType.CurveRadius, projectileMotionRadius);

Because this doesn't directly interface with gameObjects, etc. you can later switch fairly quickly to any other solution.

Attach a monobehaviour to the projectile which has a few parameters and an update function.
startTime = Time.time; // assign time when projectile is created
normalizedProjectileTime = (Time.time - startTime) / lifeTime;
if (normalizedProjectileTime > 1.0f) KillProjectile();
transform.position = Interpolate(projectileStartPos, projectileEndPos, normalizedProjectileTime);

This can later be executed on an entire array without having the gameObjects.

You should now have moving projectiles. Using gameObjects, but very easily switchable to a fully custom solution later.

The important concept here is that the projectile motion types are fixed, containted within the enum ProjectileMotionType. What this gives you is fully deterministic projectile motion with no accumulation error. This also lets you create a chain of projectiles "in the past", which is super important for a chain of projectiles emiting from a source. Otherwise, you end up with non-uniformly staggered projectiles. You can apply all sorts of easing functions to this to make it look nicer at very little cost.

Additionally, because the motion is procedural, collision detection becomes considerably easier to perform later. Post again later if you decide to try this out and I'll go into more detail for the subsequent stages.

Tochas

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Recommended method for simple particle effects?
« Reply #13 on: December 13, 2012, 05:36:04 am »
This sounds like the thing I need!!!
more detail would be appreciated

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Recommended method for simple particle effects?
« Reply #14 on: December 13, 2012, 12:53:12 pm »
I suggest getting the first stage working first as per the previous post. Once you have the core system working I'll post in more detail to help with the next stages. If you have specific implementation questions I'll be happy to help :)