Creating the Bow and Arrow in "Forgotten Memories"

  Author: Jared Barker

Date: March 8, 2023

5:09 PM EST

Xodius Studio Blogs:

Creating the Bow and Arrow in "Forgotten Memories"

The Problem:

The problem I encountered when creating the bow and arrow is that when creating it in C++, there were collision bugs that brought so many problems when firing the arrow. The main issue is that when the player steps on the arrow, it makes the player and the camera shake or have the player flying off the level.




This can be a huge problem because not only would it make it difficult for the other programmers to debug, but it can be a huge problem for the player when they try to use the bow and arrow and it bugged out on them.

The Solution:

The solution I found is a bit of a long one. So what I did is that I recreated the bow and arrow into blueprints.

So to start off, I made the bow blueprint. 
In that blueprint, I created 3 custom events for the charge and in those events, it has a timeline that plays for 1.5 seconds. After that, it sets the charge amount and print's out "charging" for debugging purposes. Next, I created an event that fires the arrow from the Arrow actor and detaches it from the Bow actor. Once that's done, it calls the fire event from the arrow blueprint and calls the stop charge

Next is the Arrow blueprint. 
In that blueprint, some functions are created that included the ArrowState variable (Thar variable was created with the state I created). This is where I used the bow charge and the ArrowState to have the arrow fire while the collision deals with the HandleOverlap call and the SetState in the Event Graph:
  • OnStateBegin: Switch on ArrowState Enume and set's the arrow collision for each state. In the "InAir" state, it adds the projectile components and sets the velocity and impulse.



  • OnStateEnd: Use the ArrowState "InAir" and destroy the projectile component.

  • SetArrowState: Checks to see if ArrowState is not equal to the function state. If true then it calls OnEtateEnd, set the ArrowState, and calls the OnStateBegin.

  • HandleOverlap: In the ArrowState "Unobtained", it cast to the player blueprint, call the AddArrow, and destroys the actor. As for the "InAir" state, if the "Get player Character" is not equal to another actor, then it sets the ArrowState and forward vector location and attaches it to the actor from the HitResult. If it's not true, then it sets the ArrowSate and deletes the other actor.


  • Construction Script: Sets the relative 3d scale to the arrow mesh.

  • Event Graph: In FireArrow event, it set the bow charge, and set the arrow state. As for the Overlap collision begin, it calls the HandleOverlap.
  • ArrowState Enume: A set of states for the arrow.


Lastly, I had it where in the player blueprint it uses a button for the fire arrow. So if the right mouse button is held down, the bow charges the shot, and when released it shoots the arrow. Also in the EventBeginPlay, I have it spawn the bow blueprint and try to reload the bow. The last thing to know is that there are 2 functions created in the player blueprint that help get the bow and arrow working: AddArrow and TryReloadBow.
\
EventBeginPlay:


Functions for player blueprint:







And that's all of what I did to fix the bow and arrow. It's a lot of modifications, but it manages to work in Forgotten Memories. With that being said, I'll move on to get the shop mechanic working next.



Comments

Popular posts from this blog

Xodius Studios Blog #5 Notification Pop Up, Intro-Level Design, Menu Indicator, Pause Menu UI Bug, and Interaction Bug

Importing assets and animations from Unreal 5.0 to Unreal 4.27.2

AI Adventures #14 Polishing the game for demo release - "Forgotten Memories" - By Michael Marquez