Saturday, 31 May 2014

Prototype - Adding Shotgun

There is couple of weapons that I would like to add. After adding shotgun I can start working on enemies and gameplay (I should do that btw) but I promise to add weapons first.

What I will do:
- Add shotgun that will fire couple of shells,
- Projectiles will bounce,
- Add damage variables to Shotgun and Reaper,
- Add spread to Shotgun and Reaper,

As I said earlier the game will be about surviving - there will be couple of enemy types and each type will have his weak point, that will motivate player to change weapon during gameplay. 

Add Shotgun and enable projectile bouncing
if you weren't reading earlier post please read how I have added Reaper weapon.


Here's great sci-fi weapon pack from Stronghold Creative
Sci-fi weapon pack from Stronghold Creative. Easy to import to UE4!
You will need to:

  • Add another variable to your WeaponType Enum,
  • Add new socket for Shotgun,
  • Use your ChangeWeapon function to set static mesh and attach weapon to socket,
  • Change Posts Begin Play function to use Shotgun, not reaper.
At this point you will have your Shotgun spawned in game. Create a copy of MyProjectile and name it Shotgun_Projectile. Open it.

1. Break link from Post Begin Play - we will use different settings there,
2. In Event Hit - destroy link to Spawn Emitter and Play Sound,
3. Go to Components,
4. Select Projectile Component,
5. Find projectile bounces category and set it to true, leave values as it,
Basically Epic created bounces for us so you don't even do it by yourself like here:
You can implement bounciness like this but it isn't needed. UE4 can do it for us.

6. Go back to MyCharacter blueprint and implement shoot functionality for shotgun. Just simple spawn Shotgun_Projectile. You can test out bouncing at this point.
Add spread to Shotgun and Reaper
Do the same on both weapons for spawning Projectile translation.
Epic have another way to do this:
I won't use Epic approach (don't have time to copy it), but if you want you can use it.

You should float variables for each weapon - Spread. So we can upgrade this later. Remember that they need to be "-" for example "-0.1" because we ABSing them.

So here's my final function for Spread.




Shotgun - firing couple of shells 
This will be super easy. First create int variable Shells and set it to 6.

1. Create For Loop block before spawning Shotgun Projectile,
2. Assign Shells to LastIndex,
3. Use For Loop to spawn Projectiles as here:
Shotgun functionality is almost ready. There is one problem - projectiles will collide with each other when spawning. You can fix that by:
1. Go to your Shotgun Projectile,
2. Select Collision Component and disable Projectile Collisions like here:



Add Damage - Reaper
Open MyCharacter blueprint and add two int variables: Reaper_MinDamage (default 20) and Reaper_MaxDamage (default 40) add those variables to Weapon_Reaper category. It will be easier to find them later.

Open MyProjectile blueprint (which is Reaper projectile) and add the same variables. Make sure Expose on Spawn is set to true for both of them.


Go back to MyCharacter blueprint and update Spawn Actor MyProjectile block. You will see created variables in MyProjectile. Connect Reaper_MinDamage and Reaper_MaxDamage to it.

In MyProjectile create Rand Range block and assing Min and Max damage variables to it. You can use Print String to check damage variables.
That's all for now - we will use those variables when dealing damage to enemies and when upgrading weapons.

Add Damage - Shotgun
Just do the same like in Reaper. Try by yourself!

So yeah we have an Shotgun functionality ready! Experiment with different settings to get better results. (you should change lifetime of Shotgun Projectile to lower value - you can change that in Defaults -> Initial Life Span.) 
Another thing is that you can limit bounces using int like here (it's event hit from shotgun projectile):

Here's shotgun functionality:

In next post we will be adding effects to it and different recoil. 

Due to refactoring I'm moving to new blog which can be found here: www.shootertutorial.com

See you there!

Prototype - First Weapon Polishing

So we wan't to create an feeling of shooting the weapon. For now it's just not fun to shoot. 

What can we improve to have better quality:
  • MuzzleFlash effect, 
  • More visible trail,
  • Impact effect,
  • Add effects to weapon itself,
  • Recoil,
  • Lighting effects (will be hard to do in mobile but we will try)
You should view this amazing tutorial about creating projectiles.

Muzzle Flash Effect.
I will use content from Strategy Game here so you need to copy content from it to your project. When you copy the content create duplicate of this particle: ParticleSystem'/Game/Environment/Effects/particles/Arbalest_Projectile.Arbalest_Projectile'

1. Open duplicated particle,
2. Disable "glow" and "particle emitter" emitters:

3. Select Required for "Tail" emitter and change values like in screenshot:

4. Select Spawn and change:
Rate -> Distribution -> Constant to 55
Rate Scale -> Constant -> 1
Burst List -> Count 0

Burst List -> Count Low -1
Burst List -> Time 0
Burst Scale -> Constant 1
5. Select Initial Size and change:
Start Size -> Max X: 10, Y: 25, Z:10
Start Size > Min X:7, Y:25, Z:4.5
6. Select Lifetime and change:
Distribution -> Min 0.05

Distribution -> Max 0.05
Can Be Baked -> false
7. Select Initial Velocity and change:
Start Velocity -> Distribution -> Max X:-500, Y:0, Z:0
Start Velocity -> Distribution -> Min X:-300, Y:0, Z:0
Start Velocity Radial -> Min: 0, Max 0,
8. Select Initial Location and change:
Distribution -> Max X:2, Y:0, Z:0 - the same for Min
9. Select Initial Rotation and change Distribution Min to 0 and Max to 1.
10. Select Size By Life and copy variables from the screenshot:


11. Leave Initial Color unchanged,
12. Leave Scale Color / Life unchanged,
13. Select Size Scale and Change it to X:2, Y:2, Z:2,

Now we need to add new Emitter in Cascade.
14. Right click on free space near last Emitter and create New Particle Sprite Emitter:
15. Chose Required,
16. For material use Material'/Game/Effects/Materials/LensFlare/M_LensFlare_02.M_LensFlare_02'
17. Screen Alignment should be PSA_Rectangle,
18. Use Local Space should be True,
19. Use Legacy Emitter Time should be False,
20. Emitter Loops should be 1,
21. Chose Spawn,
22. Rate -> Constant should be 0,
23. Rate Scale -> Constant should be 1,
24. Burst List -> Count set to 1, Count Low set to 1 and Time to 0,
25. Burst Scale -> Constant should be 0,
26. Select Lifetime and change Lifetime -> Min 0 and Max 0.1,
27. Select Initial Size,
28. Start Size -> Max -> X:100, Y:40, Z:0,
29. Start Size -> Min -> X:80, Y:30, Z:0,
30. Select Initial Velocity,
31. Start Velocity -> Distribution Min and Max XYZ should be 0,
32. Start Velocity Radial Min and Max should be 0 as well,
33. Select Color Over Life and copy variables from screenshot:
34. Right click bottom of your parameters and create Size Scale parameter:
35. Select it and use Constant X:1, Y:1, Z:1,
36. Again right click and create new parameter: Size By Life. Copy variables from screenshot:
That's all for this particle system I won't be trying to learn you Cascade because it's really advanced tool and I'm far from FX Artist, but you should try experiment with different settings to check how it's working. There is a lot of Cascade tutorials on Youtube as well. Take your time!

Before assigning this particle I will add something to the weapon.

Add effects to weapon itself
Create a copy of the same material that we have copied earlier: ParticleSystem'/Game/Environment/Effects/particles/Arbalest_Projectile.Arbalest_Projectile'

1. Open it,
2. Disable "glow" and "Particle Emitter" emitters,
3. Close Cascade and open your MyCharacter blueprint,
4. Open ChangeWeapon function that we have created earlier and in the end of your blueprint add Spawn Emitter Attached and assing copied particle that we have created like in the screenshot:
5. Go to your main blueprint (Event Graph),
6. Find the spot where you are firing and Playing Sound at Location,
7. Add new block Spawn Emitter at Location and chose the particle that we have created earlier (not the one above - the first one;))
Compile your scripts and you should have the same effect as mine. It's not perfect but for prototype it will work,



More visible trail
This will be from Shooter Example you should already have content from this project if you were reading older posts.

1. Copy this particle: ParticleSystem'/Game/Effects/ParticleSystems/Weapons/AssaultRifle/Muzzle/P_AssaultRifle_Trail.P_AssaultRifle_Trail'

2. And just change initial size of both emitters to X:15, Y:15, Z:15. That's all here. Close Cascade,

3. Open your projectile MyProjectile blueprint,
4. Create Particle System Component and assign particle that we have created. Name it Trail,
5. Go to Graph,
6. Use Post Begin Play and Set Vector Parameter of the Trail,
You should have trail now when shooting.
Impact Effect
Find P_Launcher_MF particle and create a copy, open it,

1. Disable "Tail" emitter,
2. Select Size Scale of "Spikey" emitter,
3. Change Size Scale -> Distribution -> Constant to X:1.5, Y:1.5, Z:0
4. Create new Particle Emitter,
5. In Required use Material'/Game/ExampleContent/Effects/Materials/m_flare_01.m_flare_01'
6. Screen Alignment should be PSA Velocity,
7. Disable Use Legacy Emitter Time,
8. Emitter Loops should be 1,
9. Select Spawn,
10. Rate Distribution Constant set to 20 and Rate Scale set to -1,
11. Burst List Count: 30, Count Low: 15, Time: 0,
12. Burst Scale Constant 1,
13. Select Lifetime,
14. Lifetime -> Min 0.5 and Max 1.0,
15. Select Initial Size and change it to X:5, Y: 15, Z:5,
16. Add new Sphere parameter (it will be in Location),
17. Start Radius -> Constant set to 5,
18. Velocity should be set to true,
19. Velocity Scale -> Constant set to 300,
20. Start Location -> Constant X:0, Y:0, Z:0,
21. Add new Acceleration parameter,
22. Distribution set to X:0, Y:0, Z: -2000,
23. Always in World Space should be true,
24. Add new Size By Life parameter,
25. Copy variables from screenshot,
26. Close cascade - this will be your impact particle,
27. Open projectile MyProjectile blueprint,
28. Open Graph,
29. Navigate to Event Hit,
30. Add Spawn Emitter at Loaction block and use created particle as template.
This will spawn your impact particle. Try to change variables in Cascade to get better results.

Last thing we will add to impact effect will be sound. Copy content from Content Examples and find those sounds:
Cleaver_ImpactLayerSpark01, Cleaver_ImpactLayerSpark02, Cleaver_ImpactLayerSpark03
And sounds from Shooter Example:
AssaultRifle_Shot02, AssaultRifle_Shot02_Stereo, AssaultRifle_Shot03
Copy those sounds to new folder. 

1. Create new Sound Cue,
2. Open it,
3. Try to do the same as here,
Attenuation settings:
4. Close SoundCue editor,
5. Open projectile MyProjectile and go to Graph,
6. After Spawning Impact Particle create new block Play Sound at Location and chose your sound cue you have created:
Now you should get impact effect and sound!

Recoil
As for now I will leave current animation unchanged. It isn't looking bad, should be enough for prototype.

Lighting effects (will be hard to do in mobile but we will try)
I weren't able to do this unfortunately because UE4 don't support Lighting Channels as UE3.

You can place Directional Light into your level and set it to Stationary. In Level Blueprint / or Class Blueprints you can change Light Color and Brightness, but it will cause to lit all of your objects and we want to light up only hands and weapon.

For PC you can just add spot light to your character blueprint and trigger its visibility when you are shooting - it's really simple.

I will go back to this effect when Epic will release Lighting Channels.

This is how your weapon should look like:

In next post we will add another weapon - Shotgun. We will need other weapons with different functionalities to have the game more fun to play and more challenging. 

Due to refactoring I'm moving to new blog which can be found here: www.shootertutorial.com

See you there!

Wednesday, 28 May 2014

Prototype - adding hands and weapon

NOTE: We will be adding only first weapon functionality now. Every effects / mood will be added later.

Basically it's super easy in UE4 compared to UE3 where you need to create inventory, weapons classes, projectiles - it was little bit complicated. 

Importing Hands from Shooter Example.
Copy content from Epic Shooter Example to your project. If you don't know how please read older posts. 

Hands mesh is located here: SkeletalMesh'/Game/Characters/HeroFPP/HeroFPP.HeroFPP'
Hands animation blueprint is located here: AnimBlueprint'/Game/Characters/HeroFPP/HeroFPP_AnimationBlueprint.HeroFPP_AnimationBlueprint'

Open MyCharacter blueprint (which is your player Pawn - or Character if we are using UE4 names) you will see that there are some hands already. Let's replace them. 

1. Select current hands in MyCharacter and change mesh to hands from Shooter Example,
2. Go to blueprint defaults and change animation blueprint to animation bp from Shooter Example, 
3. Change animation blueprint in hands mesh.

After compiling you will get errors from Animation Blueprint. Navigate to it and delete blocks which are causing errors. Epic were using some variables which we don't have.

If you want to use new hands in mobile you should prepare new material with Base Color and Normal only. Material from PC won't work on Mobile.

Take your time and place hand meshes from camera as you like. Mine looks like that.
Adding first Weapon
First weapon that we will add will be Reaper from DLNK. This time we won't be adding decals and effects - will do that later. As I said first we need functionality. I recommend assets from DLNK - they are cheap with great quality!

1. Add WeaponType Enum. Basically we want to support couple of weapons so we should create functionality for that.
This Enum will have all of our weapon types that we want to implement. For now just add one variable to it - Reaper.

2. Go to Hands Mesh and open it.
3. Find bone b_RightWeapon and create socket - name it Reaper_Socket.
4. Open Reaper package in Unity and import all of the fbxes and textures. You should know how to do that after importing Sci-Fi Scene.
5. Open imported Reaper_Mesh and change it build scale to 0.5,
6. Create material for your Reaper_Mesh,
7. Open Hands Mesh again and add preview mesh to created socket.
8. Click on FPP_RifleIdle anim and move your socket to get the best results.
You are done here. Now let's move into MyCharacter blueprint and setup our mesh.

1. Create couple of variables:
Weapon - type: static mesh
CurrentWeapon - type: Enum with Weapon Types that we created earlier
bWaitingForFire - type: bool
ReaperBurst - type: int default 4
ReaperSpeed - type: float default 0.2
Reaper_MuzzleFlash - type Particle System
Reaper_AmmoCurrent - type: int
Reaper_AmmoMax - type: int
You can use category to variables that are connected to Reaper.
2. Create Change Weapon function. Add WeaponType param to inputs.
3. Swtich on WeaponType input. I've couple of more weapons now you should get only one Enum there.
4. Set Static Mesh of a Weapon Variable then Attach To Reaper_Socket and update Current Weapon variable.
What this basically do is assigning Reaper_Mesh (the gun mesh) to our Weapon static mesh variable. After that we are attaching it to the socket that we have created in Hands mesh so it will move where the socket is. 
5. Go to Event Graph and use your Change Weapon Function in Begin Play.
Begin Play is something like PostBeginPlay() in UE3. It means that this event will fire up after Actor will be spawned. So when MyCharacter will spawn in game world this event will pop.

You should be getting your mesh visible in game right now.
Now let's move into shooting part. Open your Reaper_Mesh and create socket. Name it MuzzleFlash and try to have X pointing right forward the gun.
Here is entire blueprint for that. MyCharacter spawning projectiles:
I will try to explain a little bit.
1. We are checking if we can fire. Branch for Waiting For Fire bool,
2. Switch to Weapon Type and if we are using Reaper let's go further,
3. Set Waiting For Fire to true so we won't be able to spam shooting,
4. Do N block - this is really handy block. This means that we are doing something N times - this will be used for our burst mechanics,
5. Compare the counter. If it's smaller than Reaper Burst variable let's shoot,
6. If not let's stop animating and reset DO N block,
7. Montage Play - play a animation from Hands I used HeroFPP_RifleFire montage,
8. We are spawning MyProjectile in MuzzleFlash socket location that we have created in Reaper_Mesh earlier,
9. Playing some sounds,
10. Delay is used to create burst effect - you can change Reaper Speed (which we will be upgrading in the game) to make the burst faster.

That's it for shooting part. Last thing is to change MyProjectile.
1. Open MyProjectile,
2. Add new variable CharacterReference which Type will be MyCharacter. Thanks to that we will be able to get MuzzleFlash socket location to spawn other effects,
3. Mark Expose on Spawn for this variable,
NOTE: In MyCharacter blueprint when we spawn Projectile there is CharacterReference variable that we should put SELF into it,
4. Add Particle System component to Components of MyProjectile assing Template to P_AssoultRifle_Trail name it Trail,
5. Create Post Begin Play event and SetVectorParameter to ParticleSystem Component that you have created (Trail),
We are getting Character Reference from it we are taking Weapon reference and from Weapon we get socket location.
Thanks to that you will have nice trail effect when shooting.
6. Last thing is to change some parameters of Projectile.
- Projectile Gravity Scale - 0,
- Initial Speed and Max Speed - 10 000,
- Velocity X - 10000,
Your weapon is now functional! You can try with different settings for projectile, you can add muzzleflash effects or impact effects.

Here's how it looking now:
In next post we will be adding effects to this weapon. So it will feel like we are really shooting with it.


Due to refactoring I'm moving to new blog which can be found here: www.shootertutorial.com

See you there!


Sunday, 25 May 2014

Prototype - Creating Basic Scene

First of all we need an concept. Player will be standing in the middle of the corridors and he won't be able to move.

Open your project and create new default level. Place your architecture meshes like in paint draw below.

Player Start should be in the middle and pointing to L1 meshes. After placing meshes build lighting and check out if your UV channels are OK.

Some elements will need glow meshes. Place EL2_Glows mesh in the location of EL2. 

- Drop EL2_Glows inside level, 
- Lock Detail panel of placed glows, thanks to that you can select other actors in the scene without updating details info,
- Now select EL2 and press F4 this will bring up details panel in new window. Copy location from EL2 to EL2_Glows,
- Do the same with other EL2 and EL1 glows,
- You can group those meshes or create blueprint for later usage,

Next add some props to near player start. I've added boxes, barrels and core.
In Engine/EngineVolumetrics/LightBeam/Mesh there are useful light beams that you can place near your lights.

You can improve this material by adding some smoke animation.
It will look like that:
video

To do that you will need T_Smoke_Tiled_D texture from Cave Showcase from Epic. Basically you should download all of the Epic Showcases and copy assets to your content.
When copying content from other project be sure to have the same folder structure. You can't rename folders because references will broke. I have copied Content Example, Cave and Reflections to my game, there is a lot of useful assets there, and you can use it in free or commercial games. 

Next we will add smoke particles. I'm using Example Content assets. Prepared particle can be found here (I've changed couple of things to get this working on mobile): https://www.dropbox.com/s/pd4jnsfohq30ajh/FX.rar just copy it to your Game/Content. You can change particle color in material but you can create Particle Color variable and change that in cascade as well, just check out the particle material. 
video
When placing materials with alpha make sure that they aren't near player/view because they can make your performance really bad on Mobile. 

Ok so we have almost everything. Now we need to make the scene visible on Mobile Preview.

Remember: we are doing mobile game first so please use Mobile Preview when testing your scene. There is couple of things that we will prepare different way to have good quality on PC. 

Atmospheric Fog 
If you don't have any Atmospheric Fog your scene place one.
Here's my properties:

Box Reflection Capsule
Remove any other reflection capsules from your level. Place one Box Reflection Capsule near Player Start. Here's my properties:
Basically there is a problem with reflections on Mobile. That's why you should have only one placed. I've posted about this in Answer Hub - will update this later. 

ExponentialHeightFog
Place it on your level. This fog will work on Mobile. Here's my properties:
PostProcessVolume
This is important we need to disable couple of PP effect. Place it on your level and make it big so it will be surrounding your scene. My properties:
LensFlare intensity should be 0
Ambient Occlusion intensity should be 0
DOF should be disabled
MotionBlur amount should be 0
Screen Space Reflections intensity should be 0

Lighting
The most important lights will be Directional Lights. You should put 4 of them and they should be Static.
Rest of the scene should be lighted with Point Lights with Static Mode. I've one Stationary Point Light near PlayerStart to light up hands and weapon. 

Take couple of days to work around with lighting. You have all necessary information how to start. Check out UE4 lighting documentation as well!

Reflections
The last part is reflections. To your Atlas_sf add this:
You will need T_Floor_Tiles_D texture from Reflection Showcase to be able to do that. (this is the texture bottom left of the screen)

How it will look like now?


Before

After
Take couple of days to try with different settings and lights. Next post will be about adding hands mesh and first gun. 

Due to refactoring I'm moving to new blog which can be found here: www.shootertutorial.com

See you there!