Categories
Uncategorised

GD2 Blog: Week 4

Unreal and C++

As of the 25th of October, we started a new project where we experimented more with using cameras and a different style of control for our third person character.

To set up our camera so it spawns and follows, we create it within in our character’s default values (Figure 1).

Figure 1

To make sure the camera follows our player, we use a “SpringArmComponent” which our following camera will be attached to.

We can set how long the length is, which is the distance of how far away it is from the player, we can also enable camera lag which makes the following feel smoother.

Basically what this does is help the camera remain at a certain distance from the player but also not phase through other objects.

The SpringArmComponent tries to maintain its children at a fixed distance from the parent, but will retract the children if there is a collision, and spring back when there is no collision.

docs.unrealengine (2021)

This can be useful as to not get the camera stuck behind geometry that could possible obstruct the player’s view and thus hinder gameplay.

We also added some animations by using more animation blueprints and an animation instance C++ class.

In our header file, we include some variables such as our character’s movement speed and a reference to their pawn (See Figure 2).

Figure 2

In our CPP file, we set the pawn value to our character. If the pawn hasn’t been set, then it will try to return a pointer to the owner of the animation instance within the NativeInitializeAnimation void.

In the next void where we update our animation properties where we get a speed variable from our current pawn.

The next line we create a variable called LateralSpeed which only takes the speed from the pawn’s X and Y movements and leaves the Z axis out, we then get the magnitude of the speed in the next line by returning the size of our LateralSpeed.

Figure 3

In our animation blueprint, we then connect our variable to our IdletoRun state, so that we can base which animation plays off of the speed of the player.

0 would set the animation to an idle state, more than 0 sets it into a moving state where it is walking. If the speed is greater than a certain amount then a running animation will play instead.

Figure 4

Bibliography

Docs.unrealengine.com. 2021. Camera Components. [online] Available at: https://docs.unrealengine.com/4.27/en-US/Basics/Components/Camera/ [Accessed 4 November 2021].

Leave a Reply

Your email address will not be published. Required fields are marked *