Introduction to C++

Having spent a good deal of time in recent weeks working with Unreal 4’s Blueprint system, I now feel like I have a pretty solid handle on the basics of that system. Also, by looking into the guts of Advanced Turn Based Tutorial (LINK), I feel like I’m getting a better understanding of the potential of that system.

However, I wanted to get a better understanding of how C++ works in Unreal. This desire came about for one main reason; in a professional setting it is not possible (and not sensible) for me to rely on blueprints all of the time. It is important that I’m able to, at a minimum, be able to parse code and make changes to key variables in order to tweak and tune my prototypes.

c-logo

Over the next couple of weeks I’m going to post a few times about C++. My aim is to complete some available tutorials, then play with variables in order to see what effect I have and further understand the way that C++ classes work in Unreal.

The tutorials on the Unreal website seemed like a good place to start. It took a couple of minutes to get the following floating mesh up and running.

The obvious change was to increase the height of the oscillation. I did this by altering the following piece of code:

FVector NewLocation = GetActorLocation();

float DeltaHeight = (FMath:: Sin(RunningTime + DeltaTime) FMath::Sin (RunningTime));

NewLocation.Z += DeltaHeight * 20.0f;       

RunningTime += DeltaTime;

SetActorLocation(NewLocation );

 

FVector NewLocation = GetActorLocation();

float DeltaHeight = (FMath:: Sin(RunningTime + DeltaTime) FMath::Sin (RunningTime));

NewLocation.Z += DeltaHeight * 100.0f;        

RunningTime += DeltaTime;

SetActorLocation(NewLocation );

Obviously this is a tiny change, but it’s cool to see what a huge difference this makes to the end product. However, it’s very much an isolated change. I’m just changing one number randomly to see what effect it will have, rather than making a deliberate change to a variable for a calculated effect.

As such, on the next tutorial, which covers both blending between distinct camera angles whilst showing a timer, I wanted to make sure everything was in sync.

I wanted to get the camera and timer in perfect sync. I set the Countdown Timer in engine to 5 seconds, then made these changes to the code:

UPROPERTY (EditAnywhere)

       int32 CountdownTime ;

const float TimeBetweenCameraChanges =2.5f ;

       const float SmoothBlendTime = 1.5f ;

       TimeToNextCameraChange -= DeltaTime;

       if ( TimeToNextCameraChange <= 0.0f)

 

UPROPERTY (EditAnywhere)

       int32 CountdownTime ;

const float TimeBetweenCameraChanges =4.5f ;

       const float SmoothBlendTime = 0.5f ;

       TimeToNextCameraChange -= DeltaTime;

       if ( TimeToNextCameraChange <= 0.0f)

The results are here:


Now the camera arrives at it’s new position just as the timer reaches zero. The camera move is quite late and sudden, but I like to think it adds a bit of drama! There will be a couple more of these small experiments to come, so thanks for reading and C you soon (sorry … so sorry).

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s