Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

I'm having trouble with basic pawn movement in C++(I'm losing my mind)

Hi everyone. So for the past week I have been having issues making my pawn move CORRECTLY. I've looked at multiple different examples but can't get it exactly how I want.

I've tried using SetActorLocation() and had success in making my pawn move but the issue is that it has absolutely no collisions and it passes through everything.

I've tried using the AddMovementInput() but it doesn't affect the position of my StaticMesh pawn at all although the inputs are going through.

I've tried using AddActorLocalOffset() but it makes my Pawn spiral and glitch out of control.

I've tried using the PawnMovementComp's AddInputVector() but it didn't cause any kind of movement.

I really don't know how to get a desired 2D topdown movement while retaining collision. I'm losing my mind. Here is my code for reference. I am just using the SetActorLocation method right now because at least it moves right? I do not even know if this is efficient and any leads as to what I should do would be much appreciated.

 #include "FuzzyChefPawn.h"
 #include "Camera/CameraComponent.h"
 #include "Components/CapsuleComponent.h"
 #include "Components/InputComponent.h"
 #include "GameFramework/PawnMovementComponent.h"
 #include "GameFramework/Controller.h"
 #include "GameFramework/SpringArmComponent.h"
 #include "Components/StaticMeshComponent.h"
 // Sets default values
     // Set this pawn to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
     PrimaryActorTick.bCanEverTick = true;
     AutoPossessPlayer = EAutoReceiveInput::Player0;
     //Creates capsule collision as the root component
     CapsuleComponent = CreateDefaultSubobject<UCapsuleComponent>(TEXT("CapsuleComponent"));
     CapsuleComponent->SetRelativeLocation(FVector(0.0f, 0.0f, 0.0f));
     RootComponent = CapsuleComponent;
     CapsuleComponent->InitCapsuleSize(42.f, 96.0f);
     //Create static mesh component(empty)
     Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
     // Create a camera boom (pulls in towards the player if there is a collision)
     CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
     //CameraBoom->SetRelativeLocation(FVector(0.0f, 0.0f, 0.0f));
     CameraBoom->TargetArmLength = 800.0f; // The camera follows at this distance behind the character    
     CameraBoom->bUsePawnControlRotation = false; // Rotate the arm based on the controller
     CameraBoom->RelativeRotation = FRotator(-60.f, 0, 0);
      // Create a follow camera
     FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));
     FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName); // Attach the camera to the end of the boom and let the boom adjust to match the controller orientation
     FollowCamera->bUsePawnControlRotation = false; // Camera does not rotate relative to arm
     //Movement Component being added
     ChefMovementComponent = CreateDefaultSubobject<UPawnMovementComponent>(TEXT("MovementComp"));
     ChefMovementComponent->UpdatedComponent = RootComponent;
     //Critical Variables
 // Called when the game starts or when spawned
 void AFuzzyChefPawn::BeginPlay()
 // Called every frame
 void AFuzzyChefPawn::Tick(float DeltaTime)
     FVector NewLocation = GetActorLocation() + (CurrentVelocity * DeltaTime);
 // Called to bind functionality to input
 void AFuzzyChefPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
     PlayerInputComponent->BindAxis("MoveForward", this, &AFuzzyChefPawn::VerticalMovement);
     PlayerInputComponent->BindAxis("MoveRight", this, &AFuzzyChefPawn::HorizantalMovement);
 void AFuzzyChefPawn::VerticalMovement(float value)
     if (Controller != NULL)
         CurrentVelocity.X = value * VerticalMoveSpeedMultiplier;    
         UE_LOG(LogTemp, Warning, TEXT("Vert"));
 void AFuzzyChefPawn::HorizantalMovement(float value)
     if (Controller != NULL)
         CurrentVelocity.Y = value * HorizantalMoveSpeedMultiplier;
         UE_LOG(LogTemp, Warning, TEXT("Horiz"));

Product Version: UE 4.18
more ▼

asked Jan 19 '18 at 09:20 PM in C++ Programming

avatar image

2 1 3 5

avatar image staticvoidlol Jan 19 '18 at 10:34 PM

Some questions:

  • Why are you creating a new MovementComponent (ChefMovementComponent) when APawn already has one declared? (I'm assuming you're inheriting from APawn?)

  • Are you sure that the Pawn is not moving without the mesh?

  • Is it critical to use a static mesh? You could also convert your static mesh to skeletal and use the Character class, or hide the Character class' mesh and attach the static mesh there?

avatar image Chibey Jan 20 '18 at 12:12 AM

Thanks for the reply.

I'm quite new to all of this, especially C++ so any tips are much appreciated.

I tried using the move comp. from APawn but it didn't work so I just ended up adding another to see if it worked and it didn't so I should probably remove that.

I don't get the second question. If you mean, whether the pawn and the Mesh(I assigned it a random cube) are moving with the current code then, yes they are moving but have no collision.

I didn't really weigh the pros and cons of using static over skeletal. My model I plan to use doesn't have any bones but should I still use skeletal?

And final thing, how would I use the move comp. from the APawn correctly while maintaining collision?

Thanks for the reply!

avatar image ColdSteel48 Jan 20 '18 at 04:58 AM

This is the correct way to assign custom movement component https://wiki.unrealengine.com/Custom_Character_Movement_Component

avatar image Chibey Jan 20 '18 at 05:21 AM

Thank you! I'll try it tomorrow morning and tell you how it goes!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question