Sink or Swim: Navigating Water in UE5

Why?

Having a swimming mechanic will add a lot of volume to any game. In the vast expanse of game design, the inclusion of a swimming mechanic not only expands the horizons of gameplay but also delves into uncharted depths of immersion. By integrating swimming mechanics, game worlds become boundless oceans teeming with exploration opportunities. Imagine traversing expansive bodies of water, uncovering hidden treasures beneath the waves, or embarking on epic underwater quests. The addition of swimming mechanics introduces a dynamic dimension to gameplay, enabling players to access locations that would otherwise be unreachable.

Required Files

Retargeted animations from mixamo:

Process

Setting up the level and adding the water body.

To swim we of course need a body of water to use. So we need to enable the water plugin. Goto Edit > plugins and search water. Enable water (experimental) and then restart the editor.

When it restarts if you see this error make sure you scroll the the left and click on the add entry to Defaultengine.ini – this is important!

Create a basic level > remove the floor > add a basic landscape and enable edit layers.

Now we have our land scape lets add water, go to the quick add > all classes > type water > water body ocean. (or water of your choice)

If you have a problem where you cant see the water or a beach etc, it maybe the position of your waterbody and the landscape. You may need to make sure they overlap by selecting them in the outliner and moving them around and adjusting the height.

Once you can see it lets adjust the area by making a small island, to do this we can adjust the area by clicking and then moving the splines > lets just make a small island.

When we enter the water we can not swim. That’s because we don’t have anything setup to tell it how to work. If you end up walking on top of the water click on the water body in the outliner, select the physics tab and scroll down till you see Collison presents. change this option to WaterBodyCollisions

Setting up the character blueprint

Open the Character blueprint you are using.

Create two custom events called Start swimming and Stop swimming.

Lets create start swimming first, get character movement from the components menu and drag it just below the event.

from the movement node > Get player volume > set water volume > Tick water volume >

Create a new var isSwimming (boolean) > Connect it to the water volume > Tick isSwimming?

From the set swimming > Change movement mode > add character movement > change movement mode to swimming

Copy and paste everything except the event and connect it to the stop swimming. {Untick the water volume and isSwimming? And change movement mode to walking)

Swimming movement.

Next we need to modify the movement input (this is already in the blueprint.)

Find the movement input section of the blueprint and drag the IA_Move node to the left to make some space

We are going to drag in the character movement from the components section > Get movement mode > switch on EMovementMode

Connect IA_move to the Emovementmode. Click on the reveal arrow and Connect walking pin and falling pin to the existing movement blueprint. (you can make a junction/move joint and connect falling there)

Copy and paste the add movement input below the existing one.

Get control rotation > Get forward vector > World orientation (new movement input)

Connect the swimming option from our movementmode to the movement input

Connect the Y axis from the IA_Move to the movement input.

Compile and save.

Setting up the water body.

If we were to test the function of swimming now nothing would really happen as we have yet to tell the game when to start and when to stop the swimming events. To do this we need to go back to the main screen and in the outliner select WaterBodyOcean.

Next to the add button click on the blueprint button and a create blueprint dialog box will open up.

Leave the name if you would like and click on the select button and the blueprint will be created. The blueprint should open. Select event graph and delete event tick.

We now need to add a new event called ActorEndOverlap to get this event you may have to click on the ActorBeginOverlap event already on the blueprint.

ActorBeginOverlap > Cast to BP_ThirdPersonCharacter (or what ever is your character blueprint) > As BP thirdperson > Start swimming.

Repeat this process for the ActorEndOverlap however instead of Start swimming do Stop swimming. Except the event nodes.

while we are here we also should change the collision value other wise when our feet touch the water you will change to swimming animation in mid air. In details search for offset, navigate down to collision and change the collision height offset. Lets start with -70 but you may need to adjust this to your liking.

Compile and save.

If you find the water has disappeared, select one of the spline nodes and move it slightly.

We are now going test this (ignore the animation for now) you will also notice your character is sliding around a lot.

Lets fix it. Open the Character BP and open character movement and search for swimming in the details.

I feel our swim speed was ok, lets change our braking and change it to 150 this is your call what you set it to.

Setting up the Animation Blendspace

In our Main Animations folder Create a new one call swimming and import our swimming animations Swimming and TreadingWater.

Once we have imported the animations we need to make a change to the TreadingWater animation otherwise when we are treading water at the surface the water level will be at the hip height of the character.

Open TreadingWater and on the left hand side menu find transform you may need to expand it.

We want to change the last value which is the Z value of import translation to -50 then at the top click reimport animation you will notice the mannequin shift position. You can change this value depending on your preferences.

Go back a step and create a new animation blendspace and call it ABS_Swimming

Open up ABS_Swimming and Under the Asset details tab find the horizontal axis and change the name to Speed and set the Maximum Axis Value to the speed you set in the blueprint. Default is 300. Also change your grid divisions to 2 and select snap to grid.

Now on the right under asset browser find your Swim idle and drag it to the left side of the time line and then find your Swimming and drag it to the right side of the timeline.

If you hold Left CTRL and move your mouse over the time line the animation should play.

Save and Exit.

Setting up the Animation.

Open animation BP > Main state machine add new state SwimmingLocomotion.

open it > add ABS_Swimming > result > speed > right click and promote to variable

Create a new Var (bool) Swimming. Create transition lines from and to the main locomotion state and transition to will be the swimming Var.

Transition from is get the Var > NOT > Result.

Save.

Goto the event graph and on the Sequence add a new pin. Add a new movement component > get is swimming and set swimming.

We now need to setup how our the engine determines the speed of the character.

From set swimming > Cast to BP_ThirdPersonCharacter.

From thirdperson object > Try Get Pawn Owner

From thirdperson as BP third person character> Get velocity (scroll down find it under transformation) > Vector length > Set speed and connect the cast BP third person to set speed.

Now we need to go into our AnimGraph and add a swimming > not >AND (may need to create this Drag from the NOT and search AND Boolean) > Should Do IKTrace (control rig)

Now when we enter the water the swimming animation should happen, note you may need to go back and adjust the collision to your liking.

You could also setup a few more animations to smooth out the transitions this is up to you.

Conclusion

With the implementation of a swimming mechanic, you’ve unlocked a new realm of possibilities within your game world. Just as the vast oceans hold unexplored territories and hidden treasures, your game now offers players the chance to dive into untold adventures. While your swimming mechanic may require further refinement to align perfectly with your vision, it serves as a solid foundation for bringing your aquatic landscapes to life. Whether it’s navigating through sunken ruins or discovering secret underwater realms, your players will embark on journeys beyond their wildest imagination. Embrace the endless potential of your newfound aquatic frontier, and watch as your game evolves into an immersive experience like no other.

The first big goals of development

It has been a little while since I have been able to put a blog post up about the progress of Project Alpha RPG (Title in development). While I have been doing a some development unfortunately i have not been able to do anywhere as much as i would have liked to and the game is no where as far along as i would have hoped it would be since the date I started.

The main reasoning behind not being as far along as I had hoped to be is a combination of work, life and creative burn out. I am coming into a holiday period in my work and which will allow me to have a lot more free time over the next few weeks. This will be great because I am hoping to set aside enough time to develop the game to a point where i can release the first prototype of the game.

In order to get to this stage, I am happy to show a road map to prototype V01:

  • Complete mapping out Mid-town (Name in development) – 40% complete
  • Create interior’s for shops and other buildings in Mid-town – 5% complete
  • Add NPC’s and events to Mid-Town – 10% complete
  • Develop a town notice board for quests (Mid-town) – 0%
  • Generate and develop quests to be given from the notice board and NPC’s in the town – 5% complete
  • Complete Tavern (1F, 2F and cellar) Including internal quests – 60%
  • Complete Sewer, Mapping is complete however eventing and questing areas are needing to be setup (thinking about a secret shop hidden in the sewer). Overall 45% complete
  • Script NPC dialog – 15%
  • Implement dialog – 10%
  • Script at least 2 NPC’s to allow them to join the players party (have an existing NPC in mind)
  • Debug and fix battle system (calculations are preventing player taking damage) – ???%
  • Create classes for player and NPC’s (currently standard RPG MV classes) – 25% complete
  • Test and expand upon reputation system – 40% complete
  • Develop Initial Game start and basic path for the prototype – 35% complete.

Currently out of those tasks completion of this goal is about 19% overall, So lets break down each one of the goals above and establish the where I am currently up to, what I feel i need to do and thoughts on how i may expand on that at this point or maybe into the future.

Complete mapping out Mid-town

So as it stands I consider “Mid-town” to be about 40% complete and to be honest my concept drawing of the town isnt much more complete then that. as you can see by the image.

Well maybe it was a bit more complete then i remembered however I never finished it. However it did give me enough to go off to start developing it in engine with a few tweeks and changes as seen below.

From the image above you can see that it is not at all near being complete.
You can see the tavern is in the bottom section of the map and then the main town above, there are also currently two shops at the top of the map which may very well eventually move because there will be an entry to the upper town and castle. So I may alter this plan to have a guard post instead.

To the left there is a circle that will be the main guard building which will be where the player can interact with some NPCs and it could eventually also be the gaol.

To the right, there will eventually be houses that may or may not be accessible and this could also be determined by a few different variables.

For this to reach 100% completion I will need to finish painting/ building all of the buildings, foliage, water and lights. As it stands i am not sure exactly what sure what I am going to do in the lower half. I do know i want to show some sort of shanty town outside the main wall be it old run down wood buildings or tents.

Create interior’s for shops and other buildings in Mid-town

The only interior that is mostly complete is the tavern building which I will elaborate more on later in this blog.

I will need to concept a few interiors for the homes as well as the shops which will be throughout the game as the player progresses. Mid-town at current only has two other shops on the town map and that is the main shop and the weapon shop.

In the top right you can see a ladder access which takes the player to the sewer. I am planning on having these access locked until the player completes a quest that they perhaps get a key to open these access points. there is another south of this location.

Depending on the size of the outside will determine the size of the shop on the inside, in the image the general shop will be relatively small where as the weapon shop may have a back area with a smithing station. I have yet to even consider a crafting mechanic for this game. at all..

Add NPC’s and events to Mid-Town

At this stage in development there is only one NPC visible in the town itself and that was more to act as a reference for a little tent stall I was concepting. This particular NPC currently does not have a name nor any programming. Please feel free to leave a suggestion on their name. The sprite is also only a place holder for now and may eventually change.

Overall I would like to add at least a dozen NPC’s that will wonder around the town and that just grunt or utter pleasantries to the player.

I would also like at least four or five NPC’s that will communicate more in depth and perhaps provide a quest. They may also only interact with the player after they have completed a quest for that NPC from the notice board.

Develop a town notice board for quests (Mid-town)

Firstly I need to prototype this concept further and find or create some sort of sprite for it to be in the town itself either in the town center or near the stairs the player has to climb to enter the town proper. The only thing I have close to this concept is a note on the wall in the tavern. So I will need to setup an event and script a choice function for the player to select quests from the board.

I would really like to have a pool of quests that this board could call upon randomly and display five or so at a time.

So there is a little bit to figure out with this goal as well as seeing if i can integrate it with the already present quest tracker (I am considering doing a separate post on this)

Generate and develop quests to be given from the notice board and NPC’s in the town

For the quest board to be usable there needs to be quests for it to show to the player, for this to be accomplished I’ll have to brain storm at least a dozen or more ideas for quests the player can do around town such as find a missing item, catch a NPC’s run away pet or to venture into the sewer and defeat enemies or even complete bounty’s for the guard.

Complete Tavern (1F, 2F and cellar) Including internal quests

Ok so complete it almost is, alot of what the game currently has in it was tested and practiced in this little tavern and I feel that it may get a make over to the second concept image I showed in the last post.

First floor is the most complete and has NPC’s sitting at the table and one is walking around which i am thinking could be a party NPC, you’ll need to complete a few quests for that character first.

There is also a quest on the wall to collect the empty plates for the tavern owner behind the bar. for the moment the NPC is transparent and can be walked through to access the cellar however I plan to change this and add an excuse me option to their conversation tree to move them for the player to get past, this will be appear after you complete a few quests for the tavern owner. I also need to come up with a name for the NPC

At this point the 2F is complete except for NPC’s and events, I might add a few sleeping NPC’s in some of the beds which will perhaps have locked doors.

When the player sleeps at the tavern they are teleported to one of the rooms after the fade out and in.

Lastly for the Tavern is the Cellar and it is one of the more complete rooms, however I may change this to have some sort of different appearance or a chance of an enemy attack.

But for now this serves as the main entrance to the sewers which for the the prototype will be one of the main questing areas as well as the area the player can battle and level up.

Complete Sewer, Mapping is complete however eventing and questing areas are needing to be setup (thinking about a secret shop hidden in the sewer)

This by far is the biggest map in the entire prototype and the most intricate. I have probably put the most time into designing, mapping out and painting this map mostly because for this stage of development it is the main area that the player is going to operate in.

It has areas where the player steps through door ways to get through the wall and some of those doors lead to little maps inside of the sewer it self. I have toyed with the idea of having a sub cavernous area under the sewer however I have yet to decide this.

The image doesn’t show the full extent of the map however i would say this is about 20% of the final product. There will also be other aspects to the sewer and I’m planning on having a secret shop located somewhere. Currently there are active enemies which i will talk a little about below.

Script NPC dialog

As it stands there really isn’t a lot of dialog written for the game, just a couple of lines for really the only two interactive NPC’s at this point. I would like to write enough to make the game and quests interesting and not generic. I would also like most if not all interactions to have a choice to the player results may be determined by the players reputation

Implement dialog

Some Dialog has been implemented for testing purposes. however I do require most of what I will script to be implemented in game.

Script at least 2 NPC’s to allow them to join the players party

For the testers to get a good taste of what the game is meant to be like I am going to need at least two NPC’s to be able to join the players party however this is going to require the player to do some quests and increase their reputation with that person or their general reputation.

Debug and fix battle system (calculations are preventing player taking damage)

Currently the battle system works and the NPC’s take damage from the player but there are a few enemies that don’t seem to be able to damage the player, so I’m going to have to look at the calculations and do some math to get this working correctly.

Currently there are rats, bats and thieves for the player to fight in the sewer. I am not planning to have weird creatures and monsters in the game however some different enemies or allies maybe conjured or summoned by a mage or the like.

Create classes for player and NPC’s (currently standard RPG MV classes)

At the moment i am using the standard classes that come with RPG maker, While they are ok they are not complete and are only there as a base so I have started to write different classes out in my Codex book. I have yet to implement any of the classes I have written out.

At this stage for the prototype i am planning on having three different classes

  • Mercenary / Ranger
  • Knight / Paladin
  • Archer / Rogue

I will probably do a sub blog at some point to talk about these different classes however eventually I am intending on having a class upgrade system that will allow the player or NPC follows to be upgraded.

Test and expand upon reputation system

Currently I have a basic reputation system in place that when a player completes a quest it adds a certain value to global variable called reputation, yet to be implemented is the system that only allows certain interactions to occur when the players rep is over a certain amount. I also need to implement events that contribute negative reputation such as theft. once this is in place be careful because guards may come in waves to arrest you and take you to gaol

Develop Initial Game start and basic path for the prototype

So this is a hard one to plan for or to map for progress as it is the prototype as a whole, the way that I see it i would like the player to at least have a good hour or two of game play in the prototype. It will also need some clues to point the player in the right direction to move through what is playable in the first version. This means dialogue, quests, mostly complete back end systems, sound and a part story that can assist the player testing the core functions of the prototype.

Thank you for reading this blog entry into my game development series, once I am able to get to the prototype version I will be looking for testers to test and document their findings to then help with the second prototype so make sure you sign up and register to get notifications for when I do post.

For those that do want to test, I am planning to provide you with a document to complete for the prototype and I would also like to say thank you for your contribution by having you become apart of the game. So you will have your own NPC, Quest line and house which you can design yourself or by giving me some ideas on what you would like.

Until next time.

Take care.