Minigame Monday: Pathing

 Pathing:

  • The concept:

 Sorry about not putting out a minigame last week! I was suffering from a nasty cold, which luckily has mostly gone now. For this minigame, I wanted to use C++ scripting in Unreal. I started with a top down game, and was instantly interested by the pathing that the player followed when you gave it a location (in other news, I've been looking into the A* pathing algorithm, but in this game I didn't play with the algorithm, I just used it). After tweaking how the player was controlled a bit, I decided to make a maze game, where the character will automatically path, but will path into barriers that will reset their position if the player doesn't take care of them.

  • The challenge:

The big issue I faced here was finding the right Unreal API to do the things I wanted to do. At first, this project lulled me into a false sense of security; holding down the button made the player move directly to the cursor; I didn't want that, so I adapted the code so holding the button also used the pathing alogrithm; easily done. This then ended up spawning the cursor on every frame, so I fixed that (although the result was quite pretty).

A pretty result, but not what I wanted

I then moved on to creating the interactables for my game. I added an actor class called target, which would spawn a mesh and connect up some functions for overlap and collision of the mesh. I then made two child classes; one for barriers, that would respawn the player at the start, and one for the end goal. I did have to wrestle with Unreal and Visual studio to get the classes displaying correctly in both, but I managed that and got my inheritance working as I wanted. 

I then wanted to make it so that if the player hit a barrier, it would teleport them back to the spawn point, and also cancel their navigation. This behaviour wasn't too complicated, and it didn't turn out to be too complicated in code either, however finding the right functions to get the correct pointers was a right pain. Unreal documentation is not nearly as good as Unity documentation for finding functions; if there is official documentation for a function, it will only list the parameters, not give a description of how the function actually works. Despite this, I eventually managed to find the right code for the behaviour I wanted:

AGameModeBase* gameMode = GetWorld()->GetAuthGameMode();
AActor* spawn = gameMode->FindPlayerStart(0);
FVector spawnPos = spawn->GetActorLocation();
OtherActor->SetActorLocation(spawnPos);

UGameplayStatics::GetPlayerController(GetWorld(), 0)->StopMovement();

This was the code called by the barrier after it's been overlapped, and OtherActor is what's overlapping it (so here, the player). Although the end code is simple, it took me ages to find the right functions to access the spawn location!

The final bit of challenge was doing screen text for the win message, which gave me a bit of an epithany for Unreal development. Rather than using C++ or Blueprints, it's more of a question of C++ and Blueprints or just Blueprints, as doing UI with widgets pretty much necessitates using Blueprints. Once I'd accepted this, adding a widget to the viewport on hitting the goal was very simple.

  • The result:


 This game doesn't have much depth, but it all works and there's some novelty in exploring the map. I think it did its job well as a minigame, in that it exposed me to some C++ coding for Unreal. You can see what you think yourself at https://reddragonmakesgames.itch.io/pathing

Comments

Popular posts from this blog

Armageddump (Boss Rush Jam 2023)

Introducing: Minigame Monday! (3D Minesweeper)

Minigame Monday: Covert Behaviour