How to make a Spider in UE4 Part 4

Before getting the Spider to climb walls, need to to just move on the floor to start. I’ll start as simple as possible and then iterate on it as things are needed, such as keying the right animation to play based on the movement.

This may end up being helpful for someone looking to start their movement code from scratch. The reason I am putting the control code in the level blueprint is only for test. The goal of this pawn will be AI Controlled but need it will be easier to test it with key presses.

In the project settings, input, create an action mapping for the P button (Arbitrarily chosen). A public MoveForward function in the Pawn code will be called from it.

LevelBPMove

I set the speed value to a small number, 0.5, as it will be applied each tick. When P is pressed it opens a gate so that the MoveForward function is called each tick, on releasing P the gate closes.

Here is the C++ function on the Pawn.

 

In the header:

UFUNCTION(BlueprintCallable, Category = "Spider Move")
void MoveForward();

In the .cpp

void ASpiderPawn::MoveForward()
{
    FVector loc = GetActorLocation();
    FVector forward = GetActorForwardVector();
    FVector newLocation = loc + (forward * speed);
    SetActorLocation(newLocation);
}

 

Share Button

Leave a Reply

Your email address will not be published. Required fields are marked *