Pages

Tuesday, 31 May 2022

[Dev Log] Generic Slenderman Clone Part 2 // UE5 & Blueprint

So after part 1, I had the bare bones of a slenderman game. In this part I wanted to flesh out the mechanics a little more and make it start to look more like a "game". My Goals for part 2 were:
  1. Replace the cubes with actual "notes"
  2. Create random spawn points for the notes
  3. Create a sprint mechanic + realistic jump
  4. Add sprint and notes to HUD widget
  5. Change it to night time
  6. Create a flashlight
  7. Create a battery mechanic
  8. Executable
1. Replace the cubes with actual "notes"
2. Create random spawn points for the notes
For this I opened up blender and made the shittest piece of paper. Took about 1 minute. Made sure to resize the plane to A4, curled the edges slightly and gave it a material slot for the front and back and then exported it to Unreal.

[Dev Log] Generic Slenderman Clone Part 2 // UE5 & Blueprint

I downloaded the note textures used in one of the slenderman games off google images and created materials from them. Then created a way for the notes to pick one of the materials at runtime. There are 8 different textures and each note is unique:

[Dev Log] Generic Slenderman Clone Part 2 // UE5 & Blueprint

I created a new blueprint which now handles the spawning of the notes and what material they get. This blueprint contains 16 locations where the notes could spawn. More can be added but only 8 locations will be picked at runtime. You can change the number of locations in the details panel in the editor.

[Dev Log] Generic Slenderman Clone Part 2 // UE5 & Blueprint

3. Create a sprint mechanic and realistic jump
Default unreal man jumps like Princess Peach; in fact it's more floating than jumping and greatly annoys me. Fixing it is quite simple though by just changing the Z Jump Velocity in the Character Movement.

The sprint mechanic is also relatively simple. When shift is held, it reduces the sprint each second and when it reaches 0 (from 100), you can no longer sprint. It takes 10 seconds to replenish fully. I achieved this by using timers instead of ticking. That way, we're not constantly checking to see if we're sprinting (or replenishing sprint value) every frame; only when we need to.

[Dev Log] Generic Slenderman Clone Part 2 // UE5 & Blueprint

4. Add sprint and notes collected to the HUD widget
Using icons from the Android library (they're free to use) I added a progress bar and text to the HUD:

[Dev Log] Generic Slenderman Clone Part 2 // UE5 & Blueprint

The progress bar does use a binding to update itself which is expensive but barely anything is ticking in this game so I didn't really care. In UE5, the progress bars now come with a default animation as well which is snazzy. The notes text is updated when a note is destroyed and the blueprint sends a message to the HUD.

5. Change to night time
This was one of the most difficult parts as lighting in Unreal Engine is unbelievably difficult. You need to change colours determined by sun, override sky colours, change the post process volume and exponential height fog....it's never ending. Also, as the scene is so dark afterwards; I duplicated BP_Sky_Sphere so I could add a tick box which would allow me to switch between day and night in real time.

In the construction script I added this mess:
[Dev Log] Generic Slenderman Clone Part 2 // UE5 & Blueprint

Which toggles between "soft day" and night:

[Dev Log] Generic Slenderman Clone Part 2 // UE5 & Blueprint

6. Adding a flashlight
For this I simply add a spot light to the character and attached it to the head socket so it moves with the character. I thought about a doing a torch you hold in your hand but couldn't be bothered with the hand animations as this is true first person so instead, the player is wearing a head torch. I added some nodes to allow the player to toggle the flashlight on and off with F.

[Dev Log] Generic Slenderman Clone Part 2 // UE5 & Blueprint

The flashlight is its own blueprint and spawns on the player as a child component. I gave it a light profile as well using one of the default UE ones so it's softer when far away from objects; but then the cone shape starts to appear when you get closer. It always annoys me in games when the flashlight is just a circle in the centre of the screen.

7. Adding a battery mechanic
This didn't take long as it was almost copy and paste on the sprint mechanic. I added some timers to the flashlight so when it's in use it begins to lose power and it updates the HUD with the new power level. I added a cylinder to game which acts as a "battery". When you pick it up it replenishes the battery power; regardless of how much power you have left. So batteries should be used wisely as you can't store them in an inventory.

8. Executable
In the gif, "slenderman" is motionless as I disabled it's "AI" for the moment whilst testing (and I forgot to remove the debug output from sprinting) but it's starting to look more like a spooky game now!

[Dev Log] Generic Slenderman Clone Part 2 // UE5 & Blueprint

In part 3, I'll actually create the forest map, add sounds like footsteps, cracking twigs and some story elements. By the end of part 3 it will look like a proper slenderman game but it still won't act like one.

Monday, 30 May 2022

Chapter 23 // Exercises 15 , 16- Principles & Practice Using C++

In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.

Chapter 23 // Exercise 15

Describe a pattern that cannot be expressed as a regular expression.

HTML.

Chapter 23 // Exercise 16

For experts only: Prove that the pattern found in the previous exercise really isn't a regular expression.

Sunday, 29 May 2022

Chapter 23 // Exercise 14 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.

Chapter 23 // Exercise 14

Write a program that, like the one in section 23.8.7, can be used to experiment with pattern matching by typing in a pattern. However, have it read a file into memory (representing a line break with the new line character, '\n'), so that you can experiment with patterns spanning line breaks. Test it and document a dozen test patterns.


So I was confused with this one. I'm not sure if he meant, "create a new file with newlines replaced by \n" or "have a file with newlines in it". In the first case, the newline will need to be put as '\\n' in the regex pattern otherwise it will just match to the characters \ n, so the slash needs escaping. But in the second you can just have it as \n and it will continue searching the next line for the pattern.

With this in mind I decided to do both. Interestingly I discovered that if you type out a regex pattern at compile time, it will add the escape to the slash. Whereas if you type it in the console at runtime, it won't.

Saturday, 28 May 2022

Chapter 23 // Exercise 13 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.

Chapter 23 // Exercise 13

Does dot (.) match '\n'? Write a program to find out.


Using regex101.com, it shouldn't match. (.) and '\n' are completely seperate. I used regex_replace to also show how they don't match. 

A part of me though feels like this is trick question. Maybe it's not, it's one of those seemingly simple things designed to catch you out....or maybe I'm just overthinking.

Friday, 27 May 2022

Chapter 23 // Exercise 12 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.

Chapter 23 // Exercise 12

Write a program, based on the program that finds lines containing dates (exercise 6), that finds all dates and reformats them to the ISO yyyy-mm-dd format. The program should take an input file and produce and output file that is identical to the input file except for the changed date formatting.


Had a look for a replace type regex and found the standard libraries regex_replace()
This will replace all matches it finds on the same line in one go. Amazing.

I then went off down a tangent using substring to replace certain parts of the string, then attempted to convert the string to time_t to convert the time_t to a particular format. I then bashed my head against the wall and simply pushed the 3 dates into a vector then concatenated them into whatever format I wanted.

This exercise took me longer than expected as C# regex can simply replace one date format with another in 1 line....if only.

To save some time I decided not to do ALL dates and changed only the mm/dd/yyyy and dd/mm/yyyy formats.

Thursday, 26 May 2022

Chapter 23 // Exercise 11 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.

Chapter 23 // Exercise 11

Modify the table-checking program from section 23.9 to see if the number of students is increasing or decreasing over the years in question.


I used the iterators in the map created from the previous exercise to easily check the totals over the years and do a quick print out on whether it was increasing/decreasing.

Wednesday, 25 May 2022

Chapter 23 // Exercise 10 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.

Chapter 23 // Exercise 10

Modify the table-checking program from section 23.9 to write a new table where the rows with the same initial digit (indication the year: first grades start with 1) are merged.


I honestly was really puzzled by this one. I guess he meant do exactly the same but while checking the lines create a new file where years are merged? So instead of seperate lines for 1A and 1B they get merged into 1? I hope that's what he meant because that's what I did.

I tried to keep things relatively simple. I originally thought of pushing back the table into a vector then erasing lines to create the table but then remembered this chapter was also about maps, not just regex. Maps can store a unique key which was perfect for checking to see if the current line had already been pushed back with the class sizes.

Tuesday, 24 May 2022

Chapter 23 // Exercise 9 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.

Chapter 23 // Exercise 9

Using eof(), it is possible to determine which line of a table is the last. Use that to (try to) simplify the table-checking program from section 23.9. Be sure to test your program with files that end with empty lines after the table and with files that don't end with a newline at all.


from_string() also has to be created for the code to work. This is found on page 853 but I added it to my running version of std_lib_facilities.

This was an annoying one to read as it's hard to determine how many tab/spaces there are in the printed book. I also had to type up the table as he doesn't provide it and made sure it matched the patterns he gave.

I also misunderstood the question and thought that he was suggesting that you could use eof() to determine newlines?? My brain goes to strange places. Anyway, I added a simple check that looks for new lines anywhere to skip them.




Monday, 23 May 2022

Chapter 23 // Exercise 8 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.

Chapter 23 // Exercise 8

Modify the program from section 23.8.7 so that it takes as inputs a pattern and a file name. Its output should be the numbered lines (line-number: line) that contain a match of the pattern. If no matches are found, no output should be produced.


This didn't require much changing from the code given; just adding in the lines to get a filename and open it.

Sunday, 22 May 2022

Chapter 23 // Exercise 7 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.

Chapter 23 // Exercise 7

Write a program (similar to the one in the previous exercise) that finds credit card numbers in a file. Do a bit of research to find out what credit card formats are really used.


So I thought credit card numbers were straight forward; literally just 16 digits separated by a space (at least that's what it is on my credit card). I never realised they were all different, I've only ever had a mastercard.

I found this site:
and decided to write patterns for the 3 most common; visa, mastercard and amex. This site was also incredibly useful:

I got a load of test credit card numbers from this site and added some more to it:

Whilst doing this I saw more posts about how regex should not be used for data validation. I even found sites like paypal providing test credit card numbers and they had all spaces stripped out.

I did check for any whitespace separating characters after the max length of the number though because, well they should be separated in a text file anyway.

Saturday, 21 May 2022

Chapter 23 // Exercise 6 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.

Chapter 23 // Exercise 6

Write a program that finds dates in a text file. Write out each line containing at least one date in the format line-number: line. Start with a regular expression for a simple format, e.g., 12/24/2000, and test the program with that. Then, add more formats.


First I copied the text from this page: 
https://help.scribesoft.com/scribe/en/sol/general/datetime.htm into a text file for testing and used https://regex101.com/ to help me create the right patterns.

After that I ended up with 5 different patterns to test various date formats including ISO. I didn't add validation to the patterns as I feel validation should be done once you have the strings, regex is just for searching.