As some of you might know to write a code in Unreal Engine we use C++. But it is not as simple as just C++. There are many functions and classes that are already made to communicate with Unreal Engine editor. Most of people use only blueprints in UE4 but I am taking part in a programming competition, I have to write at least some code for my game's logic instead of blueprints.
So I started reading documentation of UE4. I was like "That is too much", "Why I have to do this here". But after these several days I think that I finally understand something. So here I will try to explain how to make our main character jumping and walking (and also falling and stopping on the ground)
We will name it "MainCharacter".
Now we need to create a new root component to be able to attach to it rest of our components.
So we have to add:
"RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));"
to our AMainCharacter constructor in cpp file. And now we can attach our camera and our static mesh components to root component. So first of all let's create them.
"VisibleComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("VisibleComponent"));
UCameraComponent* Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));"
and don't forget to define our VisibleComponent, to do this write
UPROPERTY(EditAnywhere) will allow us to add our custom static mesh in Unreal Editor and under this line we will define VisibleComponent as a USceneComponent (don't write a semicolone after UPROPERTY).
Now we are ready to attach them:
Camera->SetRelativeRotation(FRotator(0.0f, -90.0f, 0.0f));
Camera->SetRelativeLocation(FVector(0.0f, 250.0f, 100.0f));"
We just attached our new created camera to our RootComponent, then turned it through an angle of -90° in Y and moved it 250 units in Y and 100 units in Z (so up) relatively to RootComponent.
Now if we compile it in our Unreal Editor and drag in our viewport we will see something like this.
To find out more visit the 2nd part.