Potions, Platforms, Key colors, & Enemies


We set keys to randomly cycle through different colors in the the BP_LoopsAndLists object. We did this by creating an array variable of colors and one for keys,  then creating the custom event "Change Key Color".  The Change Key Color event  shuffles the array of keys and the array of colors,  creates an integer for "Color Key Index" that gets a key from the array, creates a dynamic material instance for the key handle,  sets the material instance's vector parameter value to a reference to of the array of colors and the Color Key Index , adds one to the color key index,  and restarts the loop after a delay.  Then, on Event Begin Play, we used a sequence node so that after setting up the Simple Game Loop, it then gets a reference to the array of keys and the calls the Change Key Color function.

We set created an interface for items with a Drop, Pickup, and PrimaryAction. For the Pickup function,  we used On Component Begin Overlap to execute a "Try to Pick Up" function when the pickup trigger is overlapped by the ThirdPersonCharacterCustom, or player blueprint.  The "Try to Pickup event" tests whether the player is holding an item, and if that is the case, it gets an instance of the interface, and calls the Pickup function. 

The Pickup function places the item in the player's hand with an Attach Component to Component function, which targets the default scene route of the item blueprint. We set the Q button to check whether the player is holding an item and then call the Drop function if that is the case. The Drop function removes the item from the hand by calling a Detach from Component function with the same target, then causes the item to fall with  the "Set Simulate Physics" function for the item and "Set Collision Enabled" for the item so that it lands on the ground. The PrimaryAction function prints a string for +10 health or mana,  then destroys the item when the player presses left mouse while holding one.

We created a moving platform, which moves up, and down between two points with a delay in between. In the blueprint, we set a timeline with a float track, and two keys for point A and B. We used a Lero vector,  which set points A and B from the float track to move back and forth between positions, then uses a Flip Flop node to continue the loop. 

We created a falling platform, by adding a trigger box which causes it to fall once it is over lapped by the player. It uses the On Component Begin Overlap event which tests if the player is the one who overlapped it, and then calls an "Activate" function if that is the case. The Activate function  sets a "Ready" boolean to false so the the platform won't be reactivated until it's reset,  and  calls a "Drop" event.  it causes the platform to fall by setting a Set Simulate Physics function to target the platform, then calls a "Reset" event. The reset event that turns off Set Simulate Physics for the platform, and then uses a timeline to keep track of the starting position, then the Set World Location and Rotation function places the platform based on the position from the timeline, and sets the Ready boolean to true.  We created a transform variable called ResetTransform, and one called StartingTransform which saves the starting position on Event BeginPlay. we set these as points A and B for a Lerp transform function,  which gives the return value locations and rotations to the Set World Location and Rotation function, telling which positions to move back and forth between.

We created blueprints for an Enemy, an Enemy Spawner, and an Enemy Spawn Manager.  The Enemy Spawn Manager BP gets all the spawners, turns them into an array and calls a "Spawn Enemies" function.  The"Spawn Enemies" function creates a For Each Loop, which uses a Get World Transform  function to input the locations and rotations of the spawners into the SpawnActor node This node creates an enemy at those inputs,  the next node assigns the Spawn Manager to a "manager" variable which each enemy has instead of having to reference the Get All Actors in Class function. 1 is then added to a "Current Enemy Total" integer for tracking the number of enemies present. The Enemy blueprint uses On Component Begin Overlap event to Set Simulate Physics of the Enemy so that the player can run into the enemy and push it do the ground. Then the "RemoveEnemyAndCheck event begins, which subtracts 1 from the CurrentEnemyTotal, and checks if there are more than zero enemies present. If there are no enemies, is calls the Spawn Enemies function and creates more.

Get Coding 1

Leave a comment

Log in with itch.io to leave a comment.