My Building Escape Room additions

Hi all,

I really enjoyed this section and really learnt a lot, especially coming in as a complete C++ noob. I did try to learn from reading a C++ book a year or 2 back but gave up when I got to pointers and references, however now I feel like I really have a good handle on them.

Anyway this is a brief outline of what I did with my room:

  1. 2x Armchairs, 2x sofas and 1 table in the room. Combine one chair and table for door to open. When you get out there is one door to win the game which is locked with its trigger in another room behind a locked door.
  2. A passage through a hole in wall takes you down a level where there are more doors and rooms
  3. Here you will need to move objects around in a specific order to be able to take a statue back up to the locked room upstairs which will then grant you access to the trigger for the door leading outside.

I don’t want to go into too much detail here as it’s the code that I care about and not the game design elements.

I also added a bit of extra code into my game which allows me to edit the “PawnStrength” which is calculated against the mass of object to decided whether the player can pick up that item or not.
The idea behind this is that I will then go and add a kind of “powerup” type drink/food which increases the PawnStrength allowing it to be able to move things such as sofa, which wouldn’t have been able to move otherwise, which will be required to open certain doors.

The additional code was added to the Grab class and is very simple, looks like this:

void UGrabber::Grab()

{

auto HitResult = GetFirstPhysicsBodyInReach();
auto ComponentToGrab = HitResult.GetComponent();
auto ActorHit = HitResult.GetActor();
float HitResultMass = 0.f;

/// if we hit something then attach a physics handle
if (ActorHit)
{
HitResultMass = GetFirstPhysicsBodyInReach().Actor->FindComponentByClass()->GetMass();
if (HitResultMass <= PawnStrength)
{
if (!PhysicsHandle) { return; } // Stop crashes if no physicsHandle is found
PhysicsHandle->GrabComponent(
ComponentToGrab,
NAME_None, // no bones needed
ComponentToGrab->GetOwner()->GetActorLocation(),
true // allow rotation
);
}
else
{
UE_LOG(LogTemp, Warning, TEXT(“This item has a mass of %f and is too heavy to lift”), HitResultMass);
}
}
}

  • I set the PawnStrength as a UPROPERTY)EditAnywhere) so that I may be able to adjust it in the editor.

FOR THE FUTURE:

I am also thinking of looking into the possibility of adding some code which would allow a texture to change and display the mass of objects added onto a pressure plate so that the player may be able to see if they have put enough or not.

Privacy & Terms