C++ Flaming Object

In the final post of this mini-series I’ve moved on to a more intermediate piece of coding. This was actually my favourite project of all the C++ tutorials. Visually it was the most interesting, and actually implied a cool little game. I quite like the idea of designing Burning Monkey Ball Deluxe. It’s a higher stress, higher risk version of Monkey Ball with dire consequences for failure. Another day, maybe.

c-logo

The original code creates a ball, tracked by a spring arm camera, that bursts into flames when the player presses the space bar:

I made some changes to this, just to give it a different flavour. First I dropped the camera angle and pulled it back a little bit.


USpringArmComponent* SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT(“CameraAttachmentArm”));
SpringArm->AttachTo(RootComponent);
SpringArm->RelativeRotation = FRotator(-45.f, 0.f, 0.f);
SpringArm->TargetArmLength = 400.0f;
SpringArm->bEnableCameraLag = true;
SpringArm->CameraLagSpeed = 3.0f

 

USpringArmComponent* SpringArm = CreateDefaultSubobject <USpringArmComponent>( TEXT(“CameraAttachmentArm” ));

SpringArm->AttachTo (RootComponent);

SpringArm->RelativeRotation = FRotator(-30.0f , 0.f , 0.f );

SpringArm->TargetArmLength = 600.0f;

SpringArm->bEnableCameraLag = true;

SpringArm->CameraLagSpeed = 5.0f;

Then I decided to make the ball a little bit more pathetic. I swapped out fire and replaced it with a puff of smoke.

OurParticleSystem = CreateDefaultSubobject <UParticleSystemComponent>(TEXT (“MovementParticles”));

OurParticleSystem->AttachTo (SphereVisual);

OurParticleSystem->bAutoActivate = false;

OurParticleSystem->SetRelativeLocation (FVector(- 20.0f, 0.0f, 20.0f));

static ConstructorHelpers ::FObjectFinder< UParticleSystem> ParticleAsset (TEXT( “/Game/StarterContent/Particles/P_Fire.P_Fire” ));

if ( ParticleAsset.Succeeded ())

{

OurParticleSystem->SetTemplate (ParticleAsset. Object);

}

 

OurParticleSystem = CreateDefaultSubobject <UParticleSystemComponent>(TEXT (“MovementParticles”));

OurParticleSystem->AttachTo (SphereVisual);

OurParticleSystem->bAutoActivate = false;

OurParticleSystem->SetRelativeLocation (FVector(- 20.0f, 0.0f, 20.0f));

static ConstructorHelpers ::FObjectFinder< UParticleSystem> ParticleAsset (TEXT( “/Game/StarterContent/Particles/P_Steam_Lit.P_Steam_Lit” ));

if ( ParticleAsset.Succeeded ())

{

OurParticleSystem->SetTemplate (ParticleAsset. Object);

}

Finally, I got the the ball to move a little bit quicker.

FVector DesiredMovementThisFrame = ConsumeInputVector ().GetClampedToMaxSize( 1.0f) * DeltaTime * 150.0f;

if (! DesiredMovementThisFrame .IsNearlyZero())

{

FHitResult Hit ;

SafeMoveUpdatedComponent (DesiredMovementThisFrame, UpdatedComponent ->GetComponentRotation(), true, Hit);

 

FVector DesiredMovementThisFrame = ConsumeInputVector ().GetClampedToMaxSize( 1.0f) * DeltaTime * 250.0f;

       if (! DesiredMovementThisFrame .IsNearlyZero())

       {

              FHitResult Hit ;

              SafeMoveUpdatedComponent (DesiredMovementThisFrame, UpdatedComponent ->GetComponentRotation(), true, Hit);

 

The result is:

One of the sections of code that really has made a lot of sense to me is the Spring Arm camera. Not only does the code line up beautifully with what is presented in-engine, with every piece layered on top of the previous, the effect is really cool, really professional, and a good addition to my armoury. I have plans for a 3rd Person level and I will see if it’s possible (or required) to add in this functionality.

This exercise has emphasised, again, that code is like any langauge; the more time you spend with it the easier it is to understand. To be frank, I’m still in a position where I would need to google the code I need in almost all situations. However, I’m not marketing myself as a coder, so I think that’s OK. What I can say, with confidence, is that I can look at .cpp and .h files in Unreal 4 and isolate the key variables and statements and tweak them to my requirements. I think that this puts me in a stronger situation than I was before I started this work. A step forward, then.

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