How to automate character movement?

Hi, I want to make the first person character move forward one step and backward one step, and turn right 90 degrees automatically when the game starts.

Is there any way to do this?

Hello reward,

this solution is designed to illustrate the point and I do not recommend leaving this as a permanent design. Here it goes:

Make sure your character class has the following properties:

UCLASS()
class AFirstPersonCharacter : public ACharacter
{
GENERATED_BODY()

float TotalTime;

UPROPERTY(EditAnywhere, Category = Startup)
float MoveFrontTime;

UPROPERTY(EditAnywhere, Category = Startup)
float MoveRate;

UPROPERTY(EditAnywhere, Category = Startup)
float TurnTime;

UPROPERTY(EditAnywhere, Category = Startup)
float TurnRate;

public:

virtual void Tick(float Delta) override;

};

In your implementation of the tick method:

void AFirstPersonCharacter::Tick(float Delta)
{
    Super::Tick(Delta);

    TotalTime += Delta;
    if(TotalTime < MoveFrontTime)
    {
        AddMovementInput(GetActorForwardVector(), MoveRate);
    }
    else
    {
        if(TotalTime < 2 * MoveFrontTime)
        {
            AddMovementInput(-1 * GetActorForwardVector(), MoveRate);
        }
        else
        {
            if(TotalTime < TurnTime)
            {
                 AddControllerYawInput(TurnRate);
            }
        }
    }
}

A better design would be to encapsulate this behaviour in a class, for instance a component, and attach the component to your character. When it is done it detaches itself.

Thanks a lot!