I wanted to have a little something to mark starting out on my journey to become a game dev. I'd been trying to learn C++ for a while, but found the process so boring. So, I decided to do something a bit more hands-on and start a course on using C++ in Unreal Engine.
I was questioning if I was meant for game dev because of how tedious and monotonous it all felt. It would have broken my heart if I weren't, because I love games so much, and this was the first time I realized what I wanted to do with programming as a career. But I was mainly going through the basics, which were things I knew backwards and forwards after years of coding in other languages, so it's not surprising that I was bored.
I finally hit a lesson on the Tick function and was shown how to move a platform. They showed how to move it in one direction, but nothing else. I wondered if I understood how it worked well enough to have the platform switch directions at a certain point, and tried implementing it. IT WORKED! I was so happy! And then I immediately checked to see if I could also get the platform to pause at each end of its path, AND THAT WORKED TOO!
I know it's going to be a really hard journey going in, but to be filled with excitement at the idea of experimenting with code for the first time in years is so validating and relieving.
I also thought I'd post the code I used, both to be able to look back at my progress after some time, as well as in hopes that maybe some more experienced people might give me tips on things I can do in the future to make this more efficient, easier to read, fewer lines, etc.
void AMovingPlatform::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if (!IsPlatformStill)
{
if (IsMovingLeft)
{
TestVector.X -= 1;
//Determine if the platform has reached the end of its path
if (TestVector.X == -410.0f)
{
IsMovingLeft = false;
IsPlatformStill = true;
}
}
else
{
TestVector.X += 1;
//Determine if the platform has reached the end of its path
if (TestVector.X == 220.0f)
{
IsMovingLeft = true;
IsPlatformStill = true;
}
}
SetActorLocation(TestVector);
}
else
{
PausePlatform += 1.0f;
//Determine if time platform has paused is up
if (PausePlatform == 150.0f)
{
PausePlatform = 0.0f;
IsPlatformStill = false;
}
}
}