Announcement

Collapse
No announcement yet.

How to Spawn Apex Destructible and Set Material using UnrealScript

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

    How to Spawn Apex Destructible and Set Material using UnrealScript

    Dear Everyone,

    First of all I want to thank:

    Spoof - for recommending modifying existing destructible component in apex class
    Daimaku - for starting thread that I was also working on and discovering to use only Asset= in the extended version of the apex destructible.

    My own contributions to this research were:

    1. figuring out how to set the collision on the apex destructible pieces once you shoot the destructible
    2. figuring out how to set the exterior and interior materials of the apex to anything you want WHILE in-game.

    ~~~

    What This Code Can Do For You

    Using the code I am presenting here, I have succeeded in (with the help of Spoof and Daimaku)

    1. Spawning Apex Mesh in Level
    2. Shooting mesh with custom class or regular projectiles
    3. Having the pieces of apex mesh rebound off of level geometry properly
    4. Enabling player to click on a mesh in my level, and then setting the Apex mesh to that new material.

    In other words, enabling you to dynamically set the Apex Mesh's materials to anything you want while in-game!

    Including the inside parts of the destructible pieces!


    5. Ability to set the inside materials of fracture pieces to a DIFFERENT material than the main mesh

    ~~~

    Custom Apex Destructible Class

    Again, this class was created with wonderful assistance from Spoof and Daimaku

    Code:
    class JoyfulDestruction extends ApexDestructibleActorSpawnable
    placeable;
    
    //Call this after you have created the Apex Destructible
    function joyfulSetMaterial(Material outside, Material inside) {
    	if (outside == None || inside == None) {
    		`log("joyfulSetMaterial: sent invalid materials");
    		return;
    	}
    	
    	StaticDestructibleComponent.SetMaterial(0, outside);
    	StaticDestructibleComponent.SetMaterial(1, inside);
    }
    
    defaultproperties
    {
        //thank you Spoof!
        Begin Object name=DestructibleComponent0
    
    
            //change to your asset, look up entire path of your APEX by going into UDK
            //right click on your APEX and get the full name, copy into your code
            Asset = ApexDestructibleAsset'JoyfulPackage.Destruction.CubeCutOut256'
    		
            //sets collison/colliding on fracture pieces of Apex mesh
            //I looked this up in Engine/ActorFactoryApexDestructible.uc 
           //and added "RB" to front of "CollideWithChannels"
    	RBChannel=RBCC_EffectPhysics
    	RBCollideWithChannels={(
               Default=TRUE,
               BlockingVolume=TRUE,
               GameplayPhysics=TRUE,
               EffectPhysics=TRUE
            )}
        End Object
    
    }
    ~~~

    Spawning the Apex Destructible

    Code:
    local JoyfulDestruction d;
    local Material m;
    
    //replace with your material, look up full path in UDK
    //same way as above for Apex mesh
    m = Material'JoyfulPackage.DestructionMaterials.Blackrock02_destructionmat';
    
    //be sure to replace the your. with whatever 
    //vectors or Actor you want to use	
    d = Spawn(class'JoyfulDestruction',,, your.Location,your.Rotation);
    
    //change second m to something else to have different inside
    //fracture material
    d.joyfulSetMaterial(m, m);  //yay!
    
    //debug info
    `log("apex mesh created and materials set");
    ~~~

    Dynamically Loading Materials to Set to Apex Mesh

    Please see this tutorial of mine as to how you can dynamically load different materials.

    http://forums.epicgames.com/threads/...While-In-Level

    This is how I enable player to click on one mesh with one material and set the apex mesh to that material.

    ~~~

    Using Custom Projectiles to Shoot Apex Mesh


    You have to tell the Apex engine to recognize your custom class projectiles as able to do damage and impart momentum to ALL apex destructibles, this is not specific to any 1 apex destructible


    1. Go into UDK
    2. click All Assets
    3. do a filter for apex
    4. Find the Apex Destructible Damage Parameters
    5. Double click on it and add a new element (green + sign)
    6. set the Name to be the name of your class, just the name itself
    7. set the values, make sure the momentum is something like 2000 or so
    8. Set base damage to something like 100 and radius to something like 50
    9. SAVE THE APEX PACKAGE by right clicking on the thing you just edited and click save

    ~~~


    Have fun spawning apex meshes in your level and setting the materials any time you want!



    Rama

    PS: Please post if you find this code useful so others find it easily too!

    #2
    evernewjoy you know how to remove the collision from the spawned chunks?

    Comment


      #3
      Dear Daimaku,

      What exactly is your goal?

      Do you just want to have pawns not be blocked by them?

      Or you want them to fall through level?

      Or you want KActors to not be blocked by them?



      Rama

      PS: something I've learned about apex destructibles, all the pieces and the whole thing seem to count as one object somehow, when I do tests for the bounds/collision extend of each apex mesh

      So if you just want to turn collision off, you can turn it off I believe, but only for the entire thing all at once.

      That's what I know so far anyways


      I played with all the following and succeeded in making projectiles pass through apex mesh, and perhaps pawns, but I was testing with a KActor. Kactor collision still occured

      Code:
      d = Spawn(class'JoyfulDestruction',,, joyWallManifestor.Location,joyWallManifestor.Rotation);
      d.joyfulSetMaterial(Material'JoyfulPackage.DestructionMaterials.Blackrock02_destructionmat', Material'JoyfulPackage.DestructionMaterials.Blackrock02_destructionmat');
      
      	
      //add to array
      levelDestruction.addItem(d);
      
      //d.SetCollisionType(COLLIDE_NoCollision);
      //d.SetCollision(false,false);
      d.StaticDestructibleComponent.SetActorCollision(false, false);
      d.StaticDestructibleComponent.SetBlockRigidBody(false);
      d.StaticDestructibleComponent.SetNotifyRigidBodyCollision(false);
      d.StaticDestructibleComponent.SetRBCollidesWithChannel(RBCC_Default,false);

      Comment


        #4
        i need my pawn not to be blocked bu them, because i'm breaking a wall to go through it, but right now the chunks are blocking my pawn and i need to jump the chunk, the goal is go throught the chuncks and avoid the jump because my player can't jump, he only can walk or run.

        Comment


          #5
          See below, the solution I think you want is option 3

          ~~~

          well try my code and let me know (actually dont, read below), I know projectiles went right through it, but that could be a problem if you still need to shoow

          there are things that are much more useful methinks

          Below is what I use in my levels to clear large amounts of fractures (debris) out of way:

          ~~~

          More Elegant / Pretty / Happy / EASY SOLUTION


          1. Change the MINIMUM MOMENTUM in the APEX settings inside udk, so that when you shoot, the pieces are guaranteed to go at a minimum velocity that you set or faster.

          so when you click on your apex mesh, do a filter for "impact velocity threshold"

          set this to something like 300 and pieces will always fly around with this velocity or higher no matter what momentum is applied

          this includes if they bump into each other as they fall, causing quite the explosion effect as mesh starts to break and pieces hit each other.

          this also clears the path for player.

          ~~~

          2. Change the MOMENTUM factor of your custom projectile in the apex damage map to something like 5000 so your player can just clear chuncks out of way

          ~~~

          Best Solution (easy too)

          3. Set a Maximum Lifetime of chunks to something like 30 seconds, so worst case player waits a couple seconds and then chunks disappear

          In UDK, click on your apex mesh

          do a filter for "DEBRIS"

          a. debris lifetime min = 30
          b. debris lifetime max = 30
          c. debris depth = 1 (anything below whole mesh is considered debris and will be remove within time range above)

          0 = whole mesh in original state, don't use 0 or you will never see mesh after 30 seconds into game!

          if you only want to remove smallest pieces use setting 2 or higher depending on the depth of your original apex.


          d. DEBRIS TIMEOUT = This must be checked as true for above settings to work!

          all these options are much prettier than trying to figure out how to remove collision at some point while keeping projectile colli...... gets all confusing




          Rama

          Comment


            #6
            Let me know which set of solutions you use Daimaku!

            You might even just be able to go with option 3 above!

            I used just this one option to put a rock over a cave entrance, from above, and sometimes the pieces got stuck in the opening after shooting the rock, but after 30 seconds it was all clear



            Rama

            Comment


              #7
              y tried using lifetime to 20,20 but the chunk didn't dissapear, but using a 8000 in momentum, help me to spread the chunks and walk over them, thanks evernewjoy

              Comment


                #8
                the chunks definitely will disappear if you set all of the settings I listed for you

                did you include DEBRIS TIMEOUT and DEBRIS DEPTH = 1 ?

                I've proven this works many times

                Rama

                Comment


                  #9
                  your are right evernewjoy, now work, just fine, i forgot to activate debris timeout and debris depth=1, thank you very much for all your help !!!!

                  Comment


                    #10
                    yaaay!







                    Rama

                    Comment

                    Working...
                    X