Announcement

Collapse
No announcement yet.

Spawn Multiple decals around the projectile HitLocation

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

    Spawn Multiple decals around the projectile HitLocation

    Hello there i want to spawn multiple decals on when my projectile hits something but i also want to spread them out so they do not spawn on top of each other.

    Right now i have managed to spawn two decals on top of each other but i am not sure how to modify the HitLocation to tell the other decal to spawn a little bit to the side of the first decal.

    Here is the code in question, it is my own projectile class extended from UTProjectile

    Code:
    simulated function SpawnExplosionEffects(vector HitLocation, vector HitNormal)
    {
    	local vector LightLoc, LightHitLocation, LightHitNormal;
    	local vector Direction;
    	local ParticleSystemComponent ProjExplosion;
    	local Actor EffectAttachActor;
    	local MaterialInstanceTimeVarying MITV_Decal;
    	local MaterialInstanceTimeVarying MITV_Decal2;
    
    	if (WorldInfo.NetMode != NM_DedicatedServer)
    	{
    		if (ProjectileLight != None)
    		{
    			DetachComponent(ProjectileLight);
    			ProjectileLight = None;
    		}
    		if (ProjExplosionTemplate != None && EffectIsRelevant(Location, false, MaxEffectDistance))
    		{
    			// Disabling for the demo to prevent explosions from attaching to the pawn...
    //			EffectAttachActor = (bAttachExplosionToVehicles || (UTVehicle(ImpactedActor) == None)) ? ImpactedActor : None;
    			EffectAttachActor = None;
    			if (!bAdvanceExplosionEffect)
    			{
    				ProjExplosion = WorldInfo.MyEmitterPool.SpawnEmitter(ProjExplosionTemplate, HitLocation, rotator(HitNormal), EffectAttachActor);
    			}
    			else
    			{
    				Direction = normal(Velocity - 2.0 * HitNormal * (Velocity dot HitNormal)) * Vect(1,1,0);
    				ProjExplosion = WorldInfo.MyEmitterPool.SpawnEmitter(ProjExplosionTemplate, HitLocation, rotator(Direction), EffectAttachActor);
    				ProjExplosion.SetVectorParameter('Velocity',Direction);
    				ProjExplosion.SetVectorParameter('HitNormal',HitNormal);
    			}
    			SetExplosionEffectParameters(ProjExplosion);
    
    			if ( !WorldInfo.bDropDetail && ((ExplosionLightClass != None) || (ExplosionDecal != none)) && ShouldSpawnExplosionLight(HitLocation, HitNormal) )
    			{
    				if ( ExplosionLightClass != None )
    				{
    					if (Trace(LightHitLocation, LightHitNormal, HitLocation + (0.25 * ExplosionLightClass.default.TimeShift[0].Radius * HitNormal), HitLocation, false) == None)
    					{
    						LightLoc = HitLocation + (0.25 * ExplosionLightClass.default.TimeShift[0].Radius * (vect(1,0,0) >> ProjExplosion.Rotation));
    					}
    					else
    					{
    						LightLoc = HitLocation + (0.5 * VSize(HitLocation - LightHitLocation) * (vect(1,0,0) >> ProjExplosion.Rotation));
    					}
    
    					UDKEmitterPool(WorldInfo.MyEmitterPool).SpawnExplosionLight(ExplosionLightClass, LightLoc, EffectAttachActor);
    				}
    
    				// this code is mostly duplicated in:  UTGib, UTProjectile, UTVehicle, UTWeaponAttachment be aware when updating
    				if (ExplosionDecal != None && Pawn(ImpactedActor) == None )
    				{
    					if( MaterialInstanceTimeVarying(ExplosionDecal) != none )
    					{
    						// hack, since they don't show up on terrain anyway
    						if ( Terrain(ImpactedActor) == None )
    						{
    						MITV_Decal = new(self) class'MaterialInstanceTimeVarying';
    						MITV_Decal2 = new(self) class'MaterialInstanceTimeVarying';
    						MITV_Decal.SetParent( ExplosionDecal );
    						MITV_Decal2.SetParent( ExplosionDecal );
    
    						WorldInfo.MyDecalManager.SpawnDecal(MITV_Decal, HitLocation, rotator(-HitNormal), DecalWidth, DecalHeight, 10.0, FALSE );
    						WorldInfo.MyDecalManager.SpawnDecal(MITV_Decal2, HitLocation, rotator(-HitNormal), DecalWidth, DecalHeight, 10.0, FALSE );
    						//here we need to see if we are an MITV and then set the burn out times to occur
    						MITV_Decal.SetScalarStartTime( DecalDissolveParamName, DurationOfDecal );
    						MITV_Decal2.SetScalarStartTime( DecalDissolveParamName, DurationOfDecal );
    					}
    					}
    					else
    					{
    						WorldInfo.MyDecalManager.SpawnDecal( ExplosionDecal, HitLocation, rotator(-HitNormal), DecalWidth, DecalHeight, 10.0, true );
    					}
    				}
    			}
    		}
    
    		if (ExplosionSound != None && !bSuppressSounds)
    		{
    			PlaySound(ExplosionSound, true);
    		}
    
    		bSuppressExplosionFX = true; // so we don't get called again
    	}
    }
    If there is another better way to do this please say so. I am new to UDK development and any kind of scripting/coding in general so any advice is appreciated

    If i posted the question wrong or in the wrong place i would appreciate any direction since this is my first time asking a question about code.ection since this is my first time asking a question about code.

    Oh also just a forum etiquette question.

    I have another problem i want advice on but is it best to ask multiple questions in the same post or should i make a separate post for every question?

    #2
    If you want a specific distance, just add that to the existing location vector, or you could use something like HitLocation + (VRand() * 5) for a random up to 5 unit distance

    Comment


      #3
      Originally posted by Blade[UG] View Post
      If you want a specific distance, just add that to the existing location vector, or you could use something like HitLocation + (VRand() * 5) for a random up to 5 unit distance
      Thanks for the help!

      This might be a very basic question but how do i add a specific distance to the location vector?

      Comment


        #4
        HitLocation + vect(1,1,1)

        Comment

        Working...
        X