10/02/23 - Unreal Work

In today's lesson, we continued using Unreal Engine, learning how to add in a gun which can shoot bullets out of it, that are able to hit surrounding objects.


To begin with, we first had to open up our Unreal projects that we had previously been working on, and then we had to download a gun .fbx file, which we had to drag into our contents folder within our project.

From here, we then opened up our project settings and added in two new action mappings, for Fire and Alternate Fire, connecting these with the Left and Right Mouse Clicks, respectively.

We then added in a new Static Mesh component, to the Camera component that we had previously worked on, and named this new component "Weapon". This new component, we then found the settings for, and changed the Asset from None to Gun, so that it looked like a gun. We then had to resize and move this gun on our viewport section, rotating it to be facing away from us, at an angle that looked as if our character was actually holding the gun.

Back within our Contents folder, we created a new Blueprint folder, called BP_Bullet, and within this new blueprint, we created a new function called Fire Weapon, which we then dragged into a new page of blueprints, so that we could get the function to work within our game. We connected this to a Line Trace By Channel function, which we had to make sure was set to Debug Persistent, and then dragged in our camera component, and get world location from it, and added in the remaining links from here, so that when we Left Clicked on our mouse within our gameplay, a raycast laser line would be emitted from the gun.

We then had to connect this Line Trace function to the other inputs, which would allow damage to be caused by these raycast hits. We then added in a new Sphere component within this previous Weapon component naming it Start Point, as well as a projectile component, and changed the Initial and Maximum speeds of this, so that we could see our bullet spheres flying.

We then had to go back to our viewport section of our character Movement tab, and placed the Start Point component into a rough placement of where it would look like the bullets would be coming out of the end of our gun. After this, we had to change the set life span of our bullet spheres, so that they would disappear from our screens after a couple of seconds, rather then not despawning after being shot.

Under the variables section of this sphere, we added in a new component named damage, and set its default value to be 5.0. We then connected this within the blueprints, to an apply damage function, so that when an object is hit by our bullets, it will lose five damage points.

We then wanted to create an enemy target that we could shoot at and cause damage to, so to do this, we first created a new Blueprint Actor folder, new blueprint actor, and named it BP_Target. From here, we created a new cube component, which would be our target, and within the graph options for this component, added in a new graph, named AnyDamage.


After this, we had to add in some new variable components, including a Boolean named isDead, and floats for Maximum Health and General Health. We then had to alter our target's health levels to 10, so that it would take two hits from our gun to kill our target. We then had to code in the blueprints, that would allow our target to disappear from our game world when it "dies". We did this by using branches and a Destroy Actor function, to make it work so that each hit would make the target take the five points of damage, until it eventually dies.

To finish up for the lesson, we made it so that the within the blueprints for our bullet, connected to its lifespan and On Component Hit function, we could cause damage to our targets. We did this by connecting up a Break Hit Result and Apply Damage functions to our blueprints, and connected them all up together. We then had to finally compile everything, which we had been doing throughout the day's work, and test out our gameplay world, to make sure that everything that we had worked on actually worked correctly, which luckily it did.

Comments

Popular posts from this blog

07/12/23 - HTML And Figma Alterations

10/01/24 - Final Game Session

08/01/24 - Presentation, App Updates And Game Run-through