How do I make my own movement class

Hi everyone,

I have been testing movement and all that stuff and I want to make my own movement class for a pawn. If your wondering why don’t I just use a character and that’s because I can’t replace the capsule component and it’s causing me a lot of problems. I want to do my own movement class but I don’t know how to start. I want to be able to make my own AddMovementInput function or at least make movement similar to it. I could do SetActorLocation but it’s very very laggy and bad. Any help is appertained! :slight_smile:

Where is it? I tried using AddMovementInput and it didn’t work. I’m using a custom pawn instead of the default one. I tried my AddMovementInput code on a character and it worked so that’s not the issue.

What type of behaviour / movement are you trying to achieve?

Well just basic clean movement. Just a basic walk around and jump. I got the player to rotate to the mouse so that’s fine all I need is just some basic movement.

The capsule was the auto one. No matter how much I try it never goes away since it’s the root and stuff. I’m thinking a mixture of different shapes to fit my model like a sphere for the head and cube for the body. My plan for ramps or stairs is to jump. Not a good idea but my skills are very bad. Since this is just my first game that I make on my own without a course I just want to cover the very basics and make a simple parkour game.

What shape are you thinking? Do you know why the capsule was the chosen shape? How are you planning in climbing/descending ramps or stairs with a cube or a cylinder?

There are quite a few tuts and examples of parktour styled games around. As far as I know, none of them required they to go as far as creating their own movement class or even having to change the capsule shape.

The FloatingPawnMovement class and its interaction with Pawn and PawnMovmementComponent classes clearly shows the complexity of something as simple as a simple floating movement.

If this is your first solo game, and you not that familiar with the engine’s code, you’re going to have a readlly bad time in trying to do what even experienced devs have problems with.

Good luck.

If you look at the ACharacter class (ACharacter.h and ACharacter.cpp) to see how things are done there, movement of a character is typically done using the "CharacterMovementComponent’ so you might be able to do something there too since you can create your own child class of it just like you normally would. this kind of thing is pretty tricky as it is to have “complex” collision shapes are it can become quite underperforming and could cause other issues that you will need to find solutions too. happy programming!

I was able to fix it! I wasn’t planning and making a whole character script though. Just like a simple move WASD kind of. I used FInterpTo and used a lot of FVectors to make smooth movement like AddMovementInput.
Thank you for all your help.

I know about ‘complex’ collision and how it slows down everything. I wasn’t planning on using that. I wanted use shapes like cubes and stuff instead of cylinders. I did end of fixing it. Thank you for your help.

cool we tip, you can modify the “BreakingFrictionAfterWalking” (has a value of 2048) to create a nice smooth movement along with changing other friction variables. could be something to look into.

For everyone who wants to make their own movement and stuff. Here is how I did it. Using a pawn I made a simple actor component class and I made a function called Forward. I made my first FVector called Pos which was the orginal player position. I then made my forward FVector which added Pos plus the direction forward and times this by speed which is a float. The FVector NewPos uses FInterpTo for both the X and Y for it to make it smooth. Then finally it uses set actor location and puts the New Pos in there which gives it this clean movement. If you want to have good speeds use 300.f. Hope this helps you! :slight_smile:

void UPlayerMovementScript::Forward()
{
	FVector Pos = GetOwner()->GetActorLocation();
	FVector Forward = Pos + GetOwner->GetActorForwardVector() * Speed;

	FVector NewPos;
	NewPos.X = FMath::FInterpTo(Pos.X, Forward.X, GetWorld()->GetDeltaSeconds(), 2.f);
	NewPos.Y = FMath::FInterpTo(Pos.Y, Forward.Y, GetWorld()->GetDeltaSeconds(), 2.f);

	GetOwner()->SetActorLocation(NewPos);
}

Thanks I just posted an answer showing and explaning the code that I used if you want to look into it.