Post

Visualizzazione dei post da luglio, 2017

Explosion effect - Camera shaking

Immagine
Every explosion has a shockwave effect, and this is usually shown in videogames with camera shaking . Unreal Engine has a built-in class that provides this kind of effect, so all we need to do is adding a new Blueprint class, and search for "Camera shake". I'll call it MyCameraShake . In the Blueprint editor we can change the parameters of the shake effect. What we need are the following: I set the duration to 0.4, so that it ends shaking just before the end of the visual explosion effect we created here . Now, in the usual EnemyBP editor, we can chain this effect to the ones already playing when we have a collision: The node to activate is "Play World Camera Shake", and we can assign it the class MyCameraShake . The location where the shake effect starts doesn't really matter, we can use the enemy location as we did for the particle system. The other 2 parameters to set are minimum radius: if the camera is placed within that radi...

Explosion effect - Particle System

Immagine
Today I'm going to add a cool effect to the destruction of an enemy ship: we'll see a stylized explosion and a shaking of the screen. The first thing I'm creating is the particle system that will simulate the explosion. Particle Systems in Unreal Engine are made of one emitter (or more than one for complex animations) that will spawn particles with different sizes and velocities. Particles can be sprites (simple 2D images that always face the camera) or meshes; I'm going to use sprites, so in Photoshop I'm creating a simple white blurred circle on black backgorund: This will be the main shape of our particles. Remember that in Unreal Materials, when we use images for opacity, white means full opacity, while black is full transparent; so in this case we'll see a circle with transparent background. After importing the texture in Unreal Engine as ExplosionTexture , we can create a new Material, called ExplosionMaterial . Let's define it a...

Collisions & Spawning a Blueprint class from C++ code

Immagine
In this post we learned about class inheritance. Another case in which this technique is used by Unreal Engine, is when we create a Blueprint class based on a C++ class. We did this for the map at the beginning, and now I want to do the same with both player and enemies starships. There are a couple of reasons why I came to this decision: 1) I want to add new static meshes to the base one, i.e. a simplified shadow under the hull, particle systems for thrusters, etc. and it would be a pain to create them all from code at right positions. 2) I want to use Blueprint Overlap Event to manage collisions between ships, so I don't have to check them from code. The problem here is that we can't simply grab the Blueprint class and drag it into the level, we need to programmatically spawn Actors from code; we don't have a reference to the BP class though, so how can we do it? Well, first of all let's create Blueprint classes derived from our PlayerShipClass and EnemyShi...

Enemy swarm inside a TArray

Immagine
We don't want to stop to a single enemy, do we? It wouldn't be a great challenge... so we're going to create a list of enemies, so we can manage them even when there are more than one simultaneously on the map. First of all, I want a way to spawn them randomly on the borders of the map; for this purpose, I'm going to create a line of hidden hexagons all around the map, something like this: where the white tiles are the classic ones, and the gray ones will not be rendered, and will simply be used as starting "spawn coordinates" for the enemies. At the moment, I'll do this by assigning them the value "2" in the tiles[][] array during the map creation, but later I'm going to save them in a map file, once we manage the loading of the maps from File System. Next, I need a list of all active enemies in the map. The structucture I'm going to use is a TArray, that is a dynamic list of any object. This means we don't have ...