Thursday, November 27, 2014

Unreal Engine 4 Tutorial: 180 Degrees Camera Rotation in Top Down Template

In my previous update, I had explained how to implement a 360 degrees camera rotation system in the Top Down Template using the Blueprints. If you're interested, you can check it out here:

Unreal Engine 4 Dev Update #4: Camera Rotation for Top Down Games

Yesterday as part of an experiment, I decided to try a 180 degrees restricted camera rotation system for the same using Blueprints. Well, it turns out that implementing a 360 degrees rotation system is far easier than a 180 degrees system. The additional complexity for doing this with the Timeline nodes comes from the fact that we can't do a loop in this case. As a result the starting position in the Timeline track will be a -90 degrees, while the rotation angle of the camera at level start should be 0 degree. So that makes it necessary to add a few more nodes to make sure that Timeline track starts for the first time at a rotation angle value of zero degree. I'm not sure if this is the most efficient way to do it in Unreal Engine 4. There might even be a better way to do in Matinee or with actual coding. But my method gets the job done in Blueprints, and so far I haven't come across any other methods. If I do, I'll update it in this blog. First I'll post a screenshot of the Blueprint below, as it'll make it a lot easier to understand.

As you can see, I'm using the keys 'Q' and 'E' as the input for rotation till +90 degrees and -90 degrees respectively. I use a Timeline node to make the rotation happen smoothly over time, rather than an abrupt change in the camera angle. First of all, I have created a float variable 'Time1' with an initial value of '-1.0'. I use this to see if I need to start the Timeline at t=0 or at any other specified time. This comes into play only during the first time camera rotation is used. This is because my Timeline starts at t=0 with a value of -90 degrees. At t=1, it reaches 0 degree and proceeds to 90 degrees at t=2. When the level starts, we're actually seeing the equivalent of t=1, i.e. at an angle of zero degree. But when we call the Timeline node for camera rotation, it always starts at t=0, which abruptly throws our camera rotation to -90 degrees, unless we tell it to start at t=1. So basically what I do is that, everytime the necessary input button is pressed, I check if 'Time1'=-1.0, which happens to be it's default value. Once the user has rotated the camera atleast once, I assign a value of 1.0. to 'Time1'. So basically checking if 'Time1'=-1.0 helps to see if this is the first time that the player has used camera rotation. If it is, we hardcode a value of 1.0 into 'Time1'. Then we call a sequence node to first set a new time for the Timeline with the new value of 'Time1'. Then we play the Timeline. If 'Time1' was not equal to -1.0 in the first place, we directly let it play the Timeline using the 'Play' or 'Reverse' input pins based on the player input. The Timeline then gets executed with a length of 2.00 from 0.0 to 2.0. It's a linear graph. Here's a screenshot of it:

We update the Yaw of the SpringArm Component with the key value of the Timeline throughout the 2 seconds. This continuous updating of the Yaw is what helps us to achieve the smooth rotation. Since I've done this in the Character Blueprint, I can directly access the SpringArm component to set it's new rotation. So basically that's how you get a 180 degrees restricted camera rotation using Blueprints in the Top Down template. You can see it in action in the following video:

If you're interested in seeing more of my work in Unreal Engine 4, feel free to check out my Youtube channel as I usually upload the videos there before posting updates here:

So that's it for now. At the moment, I've started working on a Turn-Based gameplay system. Will be putting updates about it soon. Until then, goodbye.

Thursday, November 20, 2014

Unreal Engine 4 Dev Update #4: Camera Rotation for Top Down Games

Hi everyone, welcome back for my next dev update, I had explained the process of implementing a Smooth Zoom functionality for the Top Down Template in Unreal Engine 4 Marketplace. If you want to check it out, you can find it here:

This time around, I'm going to explain how I implemented Camera Rotation for a Top Down Game in UE4. I've been meaning to make this one for quite some time, since I had received a few requests from my Youtube Video for the same. Since my motherboard and RAM got fried a few weeks ago, I was unable to do any work in UE4 for the past 3-4 weeks. I've ditched my old PC in the process and assembled a new one. So instead of waiting till the weekend to write all the remaining dev updates, I thought I'll get this one done with today itself.
Alright, Camera Rotation is a fairly simple process. Basically I just use a Timeline node that keeps looping after a key value of 360 degrees. This helps in giving a Smooth Rotation, rather than incremental values of say 90 degrees or so. I connect the input button press for clockwise and anticlockwise rotations with the 'Play' and 'Reverse' input pins of the Timeline node. This way, I just need a single Timeline node to go through the process. I then make a rotator using the Output track of the Timeline for Yaw and the default Pitch & Roll values of the Spring Arm component. Then I set this new rotation to the Spring Arm Component. Since I've currently implemented this in the Player Character class, I can directly call the Spring Arm component. But I might have to shift this to the Player Controller class soon. Here's a screenshot of the whole process in my UE4 Blueprint:

And below you can see the Timeline in action. I've made a track and set a range of 5 seconds, which is then set to loop. Key values are 0 at t=0 and 360 at t=5.

With that, we have a solid Camera Rotation functionality for our Top Down Game. You can see this in action here:

If you're interested in seeing more of my work in Unreal Engine 4, you can check out my Youtube channel as I usually update the videos there before posting updates here:

So that's it for this update. I'll probably do the next update on 'Implementing a HUD-Based Command System' for Top Down Games.

Wednesday, November 19, 2014

Unreal Engine 4 Dev Update #3: Smooth Zoom Functionality for Top Down Template

In my first UE4 dev update, I had written about adding a basic Zoom functionality for the Top Down template in UE4 using Blueprints. But as I had mentioned back then, I had implemented a step-by-step zoom system. You could only zoom in discrete steps depending on how many times the input button was clicked. Well that might be useful in certain cases, but I wanted to add a Smooth Zoom functionality to my game. So I went about making some changes to the earlier Blueprint. Most of the stuff remains the same, so changing to this newer version will hardly take a couple of minutes. As a result, I won't be writing much about the stuff that I had already explained in the first post. For reference, you can find it here:

Unreal Engine 4 Dev Update #1: Zoom Functionality for Top Down Template

Moving on, let's get to the topic at hand.

So basically, in my earlier post, I had made changes of 100 units to the 'Target Arm Length' of the player character's 'Spring Arm' component. In order to implement Smooth Zoom, I added a Timeline node. They allow you to make simple time-based animations. For learning more about Timelines, you can check out the official documentation here:

Unreal Engine 4 Documentation : Timelines

Alternatively, you can check out this Youtube tutorial:

Unreal Engine 4 Blueprint QuickShot - 7 - Changing Things Over Time

After adding a Timeline node, this is what my Blueprint looks like:

As you can see, instead of making discrete changes of 100 units each, I'm changing it continuously by units of 10, relative to the graph in the Timeline Node. Since I wanted the zoom to start out slow and then speed up, I've made a linear graph with respect to time. Here's a screenshot of the Timeline Node itself:

I have two key values in there: 0 at time t=0 and 10 at time t=10. I'm using the same values for both the Zoom In as well as Zoom Out Timeline. For now, I've kept the range to 10 seconds, but it hardly ever reaches that point, since I have a clamp in my Blueprint to restrict the maximum and minimum zoom. So I'll probably reduce the range to 5 seconds soon. Also I made sure that the Timeline execution always start from the beginning of the graph at each button press, by connecting to the 'PlayfromStart' input pin.

And that's it. We have implemented a simple Smooth Zoom functionality. You can see this in action in the following video:

If you're interested in seeing more of my work in Unreal Engine 4, you can check out my Youtube channel as I usually update the videos there before posting updates here:
And that's all for now. Next update on implementing Camera Rotation for the Top Down template, coming soon. Signing out.