Announcement

Collapse
No announcement yet.

How to Spawn/Attach a ParticleSystem Explosion Effect That Loops Once

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to Spawn/Attach a ParticleSystem Explosion Effect That Loops Once

    Dear Community,

    For some of you this is basic, but I could not find all this info in one place, so I'm making a compilation / tutorial

    This tutorial tells you all the steps needed to:

    1. set up your particle system to only loop once, and to loop guaranteed at the time of its spawning, and then disappear, as is needed for just about any explosion effect.

    2. spawn this explosion/particle system in-game using unrealscript

    3. attach particle effect to an actor, so that the actor does not pass through the effect as the actor moves, but instead the effect stays constantly in front so it is fully visible


    ~~~

    Part 1 - Setting Up Your Particle System

    Please look elsewhere for how to actually make a Particle System

    For each of the components of your particle system,

    you must set the Required and Spawn modules as follows:

    Required Module
    Emitter
    Kill on Deactivate = true
    kill on Completed = true

    Duration
    Emitter Duration = small number like 0.1
    Emitter Loops = 1

    ~~~

    Spawn Module

    Spawn
    Rate
    constant = 0

    Burst
    Count = 1 (use green Plus sign to add a value)
    Count Low = -1
    time = 0 (runs at time 0, which is spawning time of emitter, which we spawn in-game with code)
    ~~~

    Use the Lifetime module to control how long the single cycle of your particle effect lasts

    ~~~

    Once you have your particle system, let's say you've called it: VictoryPackage.Particles.JoyParticle

    Find out the unrealscript name of your particle system by right click and selecting "Copy full name to clipboard"

    ~~~

    Part 2 - UnrealScript

    Here is the unrealscript!

    In whatever class you want to spawn your explosion effect / particle system:



    I commented out the local variable because it is not used, but I wanted to show you how you could track the effect you created if you needed to modify it after it spawned.

    Code:
    function createExplosion(vector HitLocation, vector HitNormal){
    //local ParticleSystemComponent ProjExplosion;
    	
    	//create explosion
    	//ProjExplosion = 
    	WorldInfo.MyEmitterPool.SpawnEmitter(
    		ParticleSystem'VictoryPackage.Particles.JoyParticle', 
    		HitLocation, 
    		rotator(HitNormal), 
    		None);
    }

    look at various UTProjectile classes including the link gun to see how you can pass in the HitNormal and HitLocation for events like HitWall.

    If you just want to spawn an explosion at a specific location, use

    Code:
    createExplosion(LocationForExplosion, rot(0,0,0));
    Spawn in Front of object?
    What if you want to spawn the explosion in front of the object your projectile hit, you can use something like:
    Code:
    HitLocation + HitNormal * 96
    96 could be a variable instead, indicating the distance to spawn in front of the object, based on the angle at which the projectile hit the surface.

    3. Attach to an actor

    the final parameter of the spawning function allows you to attach the particlesystem to an actor

    Code:
    WorldInfo.MyEmitterPool.SpawnEmitter(
    		ParticleSystem'VictoryPackage.Particles.JoyParticle', 
    		HitLocation, 
    		rotator(HitNormal), 
    		YayanActor);
    make sure that in the UDK particle system editor, for each component
    Required Module
    use local space = true
    (same module as where Kill on Completed is located)

    If you want the particle effect to have the same orientation as the actor it is attached to:

    use
    Code:
    YayanActor.Rotation
    instead of
    Code:
    rotator(HitNormal)
    add some distance to keep the explosion in front of the actor, you can use actor.GetComponentsBoundingBox or just use a number depending on your needs

    Code:
    HitLocation + Vector(YayanActor.Rotation) * 96;
    Enjoooy!

    Let me know if this helps!



    Rama

    #2
    You literally just saved my team and I a crapload of trouble. Thank you for this!

    Comment


      #3
      yay!

      I'm happy to help!

      you might also want to to check out my tutorial on making a shield with a mesh that fades in and then out over time.

      i spent huge amount of time to figure out that color and alpha over time should only go from 0 to 1 even if the life span of particle is 17 seconds, the 0 to 1 in time gets mapped to the duration of the particles life.

      Comment


        #4
        hey question, how do I set things up so that every time an explosion is triggered it chooses a random effect from an array? so every explosion looks a little different.. The part in bold I want to pick a random effect from an array that I create...
        defaultproperties
        {
        ProjFlightTemplate=ParticleSystem'WP_p1llGun.Effec ts.P_WP_p1llGun_Ball'
        ProjExplosionTemplate=ParticleSystem'newglufo.FX.newexop1b'
        ExplosionDecal=DecalMaterial'june2012.Material.new impact_1'
        DecalWidth=400.0
        DecalHeight=700.0
        So, how do I declare the array variable, how do I define it (list of particle effects), and then how do I stick it in the code above? Thanks so much in advance...

        ~p

        Comment


          #5
          Code:
          var array<ParticleSystem> ProjExplosionTemplates;
          
          function createExplosion(vector HitLocation, vector HitNormal){
          //local ParticleSystemComponent ProjExplosion;
          	
          	//create explosion
          	//ProjExplosion = 
          	WorldInfo.MyEmitterPool.SpawnEmitter(
          		ProjExplosionTemplates[Rand(ProjExplosionTemplates.Length - 1)], 
          		HitLocation, 
          		rotator(HitNormal), 
          		None);
          }
          
          defaultproperties
          {
          ProjExplosionTemplates(0)=.....
          ProjExplosionTemplates(1)=.....
          }
          something like this should do the trick i think.

          Comment


            #6
            OMG thanks! ))

            Havnt tried it yet, but here is a vid of what I'm working on:

            http://youtu.be/M_XLkBExyqs

            thanks again, great work by the way!

            Comment


              #7
              Thansk a lot !

              For people like me, this is certainly not basic at all. I will try this tutorial in holiday, I will definitely need it.

              Please continue to make tutorials when you have spare time

              Comment


                #8
                Originally posted by p1ll View Post
                OMG thanks! ))

                Havnt tried it yet, but here is a vid of what I'm working on:

                http://youtu.be/M_XLkBExyqs

                thanks again, great work by the way!

                Wow! your project is very colorful!

                Looks awesome!

                Great work!



                Rama

                Comment


                  #9
                  Is there a way I can use this for my pawns when they get hit by a flame thrower?

                  Comment


                    #10
                    ya you just need to explain how your flame thrower works, does it do distance checks or does it have projectiles?



                    Rama

                    Comment


                      #11
                      ok here goes:
                      It works as an instant hit weapon.
                      I added this bood to my damage type

                      Code:
                      Var Bool bcausesflames
                      In my Parent Pawn class:
                      Code:
                      //HazerBurn
                      var ParticleSystemComponent Burn;
                      var ParticleSystem BurnTemplate;
                      var vector SocketLocL;
                      var rotator SocketRotL;
                      var name BurnSocket;
                      Var float HBurnTime;
                      
                      Function SetHazerBurn()
                      {
                      BurnTemplate=ParticleSystem'WP_Hazer.Effects.FireHitFX_PS';
                      WorldInfo.MyEmitterPool.SpawnEmitterMeshAttachment(BurnTemplate, Mesh, BurnSocket,true,);	
                      }
                      
                      Function OffHazerBurn()
                      {
                      Dont know how to turn this off yet		
                      }
                      
                      simulated function PlayTakeHitEffects()
                      {
                      	local class<SLDamageType> SLDamage;
                      	local vector BloodMomentum;
                      	local UTEmit_HitEffect HitEffect;
                      	local ParticleSystem BloodTemplate;
                      
                      	if (EffectIsRelevant(Location, false))
                      	{
                      		SLDamage = class<SLDamageType>(LastTakeHitInfo.DamageType);
                      		
                      		if ( SLDamage != None )
                      		{
                      			*snipped*
                      			
                      		    if ( SLDamage.default.bCausesBlood && !class'UTGame'.Static.UseLowGore(WorldInfo) )
                      			{
                      					*snipped*
                      			}
                      			else	
                      					
                      			if ( SLDamage.default.bCausesFlames && !class'UTGame'.Static.UseLowGore(WorldInfo) ) 
                      			{
                      					Worldinfo.Game.Broadcast(self, "!!!!!!!  I'm on Fire  !!!!!!!!");
                      					SetHazerBurn();
                      					SetTimer(HBurnTime, false, 'OffHazerBurn');
                      					
                      			}
                      				if ( !Mesh.bNotUpdatingKinematicDueToDistance )
                      				{
                      					// physics based takehit animations
                      					if (SLDamage != None)
                      					{
                      						*snipped*
                      						}
                      						SLDamage.static.SpawnHitEffect(self, LastTakeHitInfo.Damage, LastTakeHitInfo.Momentum, LastTakeHitInfo.HitBone, LastTakeHitInfo.HitLocation);
                      				    }
                      			    }
                      
                      		}
                      	}
                      }
                      
                      defaultproperties
                      {
                      
                      
                      
                       *Snipped*
                       
                       SBurnTime = 20.5f
                        
                      }


                      In my NPC Pawn Class:


                      Code:
                      defaultproperties
                      {
                      *Snipped*
                      	BurnTemplate(0)=ParticleSystem'WP_Hazer.Effects.FireHitFX_PS'
                      	BurnSocket=BurnSocket
                      	
                      	BurnTemplate(0)=ParticleSystem'WP_Hazer.Effects.FireHitFX_PS'
                      	Begin Object Class=ParticleSystemComponent Name=Burn
                        	 SecondsBeforeInactive=10.0
                      	End Object
                      	
                      	Burn=BurnTemplate
                      	Components.Add(Burn)
                      	
                      	HBurnTime = 20.5f
                      
                      }
                      I was able to get the blood to spawn when I shoot them with my bullet damage type weapon

                      Comment


                        #12
                        *** works!!! Soldier! Get your team ready to go inside while I finish off!!!

                        How do I destroy the effect after burn time?

                        Comment


                          #13
                          you need a global var

                          Code:
                          var ParticleSystemComponent burnemitter;
                          the output of this function is a reference to the created emitter

                          Code:
                          burnemitter = WorldInfo.MyEmitterPool.SpawnEmitterMeshAttachment(BurnTemplate, Mesh, BurnSocket,true,);
                          then use this code to get rid of the emitter:

                          Code:
                          burnemitter.SetHidden(true);
                          burnemitter.DeactivateSystem();
                          burnemitter = none;


                          Rama

                          Comment


                            #14
                            Thanks a lot rama

                            Comment


                              #15
                              **** it no joy

                              Comment

                              Working...
                              X