Difference between revisions of "Making a ballistic missile"

From ARK Modding Wiki
Jump to navigation Jump to search
Line 131: Line 131:
  
 
==== Decal spawn ====
 
==== Decal spawn ====
Since the decal is an actor we simply need to use the spawn actor from class node to spawn the decal at the current location of the explosion actor with an absolutely massive scale. A decal actor is invisible if there are not meshes nearby but it paints itself on meshes if they are within it's size so making it huge paints a massive area with it's decal material. Finally we destroy the explosion actor after it's performed it's role so as to not have our mod slowly eating unnecessary server ram after each nuke goes off.
+
Since the decal is an actor we simply need to use the spawn actor from class node to spawn the decal at the current location of the explosion actor with an absolutely massive scale. A decal actor is invisible if there are not meshes nearby but it paints itself on meshes if they are within it's size so making it huge paints a massive area with it's decal material. Finally we destroy the explosion actor after it's performed it's role so as to not have our mod slowly eating unnecessary server ram after each nuke goes off. The decal actor is spawned a -90 degree angle because that is the default value for decals that spawns them so they are painted on the ground primarily.
  
 
[[File:11.png|center]]
 
[[File:11.png|center]]

Revision as of 01:20, 1 June 2018

Introduction

This tutorial will teach you how to make a ballistic missile that can strike anywhere on the surface of an ark. The models for the missile silo and the missile itself were made by pleasure in his tutorial here <>.


Explanation

This ballistic missile will have several components.

The first component is the missile silo. The silo will allow you to craft ballistic missiles and then fire them. The silo will have an inventory component where you can craft a missile and a button where you can launch the missile.

The second component is the ballistic missile. The missile will be a moving actor that allows up to four passengers and it will have a launch phase, an ascent phase, a level out phase, a descent phase, and finally a terminal phase where if the missile touches anything it explodes. The ballistic missile cannot be shot down or stopped.

The third component is a locator structure. This structure will act as a target for the ballistic missile and a tribe may only have a single one placed on the map at one time.

The final component is an explosion actor. The missile itself will be able to be seen anywhere on the map however, the destruction of structures,dinos,players,and foliage uses up large amount of processing power so we make a second local actor that manages the destruction so only near by players will have to process the damage.

Setting Up

This project will include many different blueprints that will work concurrently so to start with we will create all the actors and fill out their defaults and logic one at a time. To start with make a copy of the smithy and call it Structure_MissileLauncher or something similar. We also need to make a primal structure called "BallisticMissileTarget" this will be our target structure. Then create a primal inventory component called Inventory_MissileLauncher. Next create two generic actors, one called "Ballistic Missile" and the other called "ExplosionActor". Finally create a decal actor and call it "radiation decal".

For any mod you also need primal game data which you can learn about in the ark mod community manager tutorials located in a playlist here.


https://www.youtube.com/watch?v=Ap1szFuAKxY&list=PL2o1TY9xh_JsmbgQfSCydfT-7OSdvxsVR

Building the missile silo

The Items

Redwarf already goes over the purposes of the item settings in his tutorial here. https://wiki.arkmodding.net/index.php?title=Tutorial:_Solar_Panel#Setup_the_Primal_Items. Here are the settings I changed for reference.


The missile silo item defaults

9.png

The structure

For this part of the tutorial we will be altering the copy of the smithy that we created earlier in the tutorial.

Defaults

  • Static mesh: Set this to your missile silo static mesh
  • Blueprint multi use entries: set this to true so that we can add custom multi use entries to this structure for our launch command

Making the Multi use entry

First go into the event graph and search for multi use in the search bar on the left. Then right click BPgetmultiuseentries and implement function then do the same for BPtry multi use. This will add the two multi use functions we will be working in.

Your make multi use entry should look like this.
2.png

Next go into the BPGet multi use entries graph and right click the multi use entries array output on the input of the function and promote to variable. Name the variable to local multi use. This variable will store our single multi use entry and then output it from the function. Create a make multi use entry. Set use string to "launch missile". Expand the node by clicking the down arrow and set display on inventory UI to true. This will add a button to the inventory component that lets you launch will still in the inventory. Set the use index to any number above 10,000. Keep note of this number since it will be used later. Get your local multi use variable drag off of it and make an add node then connect your make multi use node output to this add node. Link all the execution wires up together and make another get local multi use variable that connects to the output of the function.

Finally go to your BPtry multi use graph and drag off use index and create a switch on int. Make the start index for your switch the number you choose for your make multi use entry and add a single pin. Make that single pin execute your launch missile event and wire up the function. Some people like to add a force net update before the function ends to insure both the client and server are synced after the multi use is executed.

Setting up the event graph

Creating the events

To begin with the event graph you need to create three custom events(search custom event in the blueprint browser) named missile slotted, missile removed, and launch missile.(Note these can be whatever you want but I'm specifying the names for consistency in the tutorial). All three events will be reliable. Missile slotted and missile removed as their names imply will handle all the changes the launcher makes when a missile is ready in the launch vs when it's not. Therefore these two events are multicast because they will be both controlling client changes like particle effects and server effects like spawning a rocket actor when a missile is slotted. Missile launch however will run lots of logic but all the client side stuff that happens like noises are going to be taken care of the rocket itself. The missile launch event will only have to deal with the logic required for a missile launch and not it's client consequence thus it is a server side only event.

You need these three events in your event graph

Creating the variables


The next step is to create two variables that will be used in the event graph. The first variable is a boolean called "ismissileslotted?" and the second variable is a object variable of the ballistic missile we made in setting up named "Missile". The local multiuse is also a variable but it will not be used in the event graph.


3.png

Missile removed


We will now begin filling out the events. The first event we will fill out is the "missile removed" event. This event will be fired from the inventory component whenever there is no available missile items in the missile silo. So the event will start by setting the "missileslotted" variable to false and then get a reference to our "Missile" variable and destroying that actor. Finally set the value of "Missile" to none.

4.png


Missile slotted

Next up is the missile slotted event. First we set the "missileslotted" variable to true then we check if the "missile" variable is valid, if it is we already have a missile slotted thus we do nothing. If there isn't a value for "missile" or the value is broken we spawn a new missile from the launcher location + offset and set that to the new value of "missile". If we have any particle effects,sounds, or material changes for when a missile is slotted we would have those run on this event after the missile is spawned.

8.png

The inventory component

Building the targeting station

This is likely going to be the easiest part of the tutorial. By the time you get to this section of the tutorial we already have created a primal structure item and a primal structure so we will skip that part and go straight into the nitty gritty coding. I was originally going to have only one of these target structures per tribe however I thought of an even better idea only having one of these structures on the map period. I'll leave it to the imagination for what kind of sneaky things you can do with that mechanic.


Building the targeting station event graph

So for the blueprint on begin play we will have a .2 second delay to avoid a common bug that occurs when structures update too quickly after being placed. Next we check the "IsPreviewStructure" boolean to make sure this is the placed version and not the ghostly pre-placement version of the structure. Then we get all actors of class with itself being the class in this case whatever you named it. Next we do a for each loop with a break and destroy the first version of this actor that isn't itself that it can find. I would recommend instead using a reverse for each loop to get rid of all versions of this structure to take care of edge cases that may or may not exist(even if the system itself is solid other bugs in the system could somehow cause there to be more then one of this structure perhaps due to lag or clever players) but for a prototype version just getting rid of the first one it finds is enough.


10.png

Building the missile

Building the explosion actor

Defaults

- Replicates: True We set this to true for the same reasons as the missile actor.

Decal

A decal is an actor that uses a special material to apply textures to objects in the world. For this tutorial we will use a decal to make the area affected by the ballistic missile look irradiated. To start with create a material called "M_RadiationDecal". Next set the domain of the material to "DefferedDecal", this lets the material know it will be used for a decal and opens the material inputs needed for a decal.

5.png

The next step is to fill out the graph. We will have a texture sample node with our radiation texture. The output will go into the base color and the alpha will be multiplied by a exponential radial gradient node. This arrangment means as the texture gets closer to it's edges it becomes more translucent effectively turning a square texture into a circular one. The exponential radial gradient will have a constant .6 as it's radius to make the final product a smaller circle but you can set it to whatever suits your needs.

6.png

The next step is to create a blueprint of the type "DecalActor" with the decal material being the material we use in the blueprint. When the missile explodes it will spawn this decal.


The effect of the decal on a *previously* forested hill.

7.png

If you want to learn more about decals you visit the official documentation here https://docs.unrealengine.com/en-us/Resources/ContentExamples/Decals.

Setting up the event graph

This actor was originally supposed to hold all the explosion related stuff like the particle effects ect but I realized it would be cooler if you could see the explosion from anywhere on the map so this actor just contains all the functional destruction code.


Foliage destruction

Structure/Character destruction

Compared to destroying foliage annihilating all the nearby creatures,players, and structures is fairly simple. We simply do a server octree(basically a cheap node to detect nearby objects that wc added to their version of unreal 4) for structures set a temp variable to it's output then do an octree for pawns(players and creatures are both pawns) and append that output array to our temp array. Finally we do a for each loop to apply damage to all of them (another case where you would probably want to use a reverse foreach loop to make edge cases like executions happening in the wrong order *shakes fist at wc server coding* resulting in some creatures/structures being skipped). I used get primary world to get the level for the octree just because in some cases the k2 get world node which should do the same thing occasionally causes bugs.

12.png


13.png

Decal spawn

Since the decal is an actor we simply need to use the spawn actor from class node to spawn the decal at the current location of the explosion actor with an absolutely massive scale. A decal actor is invisible if there are not meshes nearby but it paints itself on meshes if they are within it's size so making it huge paints a massive area with it's decal material. Finally we destroy the explosion actor after it's performed it's role so as to not have our mod slowly eating unnecessary server ram after each nuke goes off. The decal actor is spawned a -90 degree angle because that is the default value for decals that spawns them so they are painted on the ground primarily.

11.png

Wrapping up

Sources

Missile Icon: Missile Silo Icon: https://openclipart.org/detail/82435/missile

Challenges

Using your own knowledge try to complete these challenges to improve your ballistic missile mod!

- Make the area that is nuked irradiated and have radiation cloud particles

- Make the missile's landing more graceful and realistic

- Add an anti-ballistic missile launcher to counter the ballistic missile

Conclusion