Newbie questions regarding character input

Hello, and sorry if this seems a rather helpless-sounding post to make, but I have been looking around and fiddling with my problems for a little while now.

I am completely new to Unreal Engine, and have looked at the various documentation-tutorials for movement, also looked at Tom Looman’s rather extensive survival project, but I didn’t feel like I could just dive into it right now. So currently what I wanna attempt is a decent movement/camera system.

Character class for input
So, I think I understand the use of Player Controller for Pawn movement/input, but it seems some use it for the character class, too. Is there a good reason for that? I’d otherwise just insert all input events into the actual character class.

Pawn/Character Movement

I noticed, if I simply use the UE4 documentation code for pawn input and insert it in my character, it will never stop even when not pressing down the button. It seems pretty obvious to me that this is because the FVector CurrentVelocity is never reset in the UE4 documentation. I just fixed it by adding an else statement to the MoveForward()/MoveRight() functions of which sets it to zero



void ACharacter::MoveRight(float Val)
{
	if ((Controller != NULL) && (Val != 0.0f))
	{
		CurrentVelocity.Y = FMath::Clamp(Val, -1.0f, 1.0f) * 100.0f;
	}
	else
	{
		CurrentVelocity.Y = 0.0f;
	}
}

But then, did I miss something? Because I don’t see how it actually works without resetting the CurrentVelocity inside of the UE4 documentation (Pawn Class) - Yet it does.

Mesh vs. Capsule of character
The capsule as I understand is the actual way of knowing if you are about to collide with other physical objects while the Mesh is simply an visualization of the object (Even though I guess collision can be trigged somehow with the mesh?).
So in my case, I simply added the UE Mannequin skeleton as mesh, and the model ended up standing in the middle of the capsule, which meant it was floating in the air (I would love to upload a picture, but apparently it is harder than I imagined). I decided to simply move the Mesh component in the editor (Moved it in the Z-axis), until it was “standing” on the floor. Are there any other, more efficient way of doing this? Perhaps in code - or is this simply faster in the editor?

I come with a small background in C++, and that is really the biggest reason for me to try and implement things in C++ in UE4. I have not looked at blueprint as of yet, but I probably will, when I feel somewhat able to stand on my own, at least some of the way. Sorry if there are any duplicates of the questions.

Regards,
Boooke

the PlayerController is the “mind” of the player. When you press your “Forward” key. It’s basically like telling your legs to walk, right? But if you’re sitting in a car, and you press “Forward” you don’t want to be walking, you want to be pressing the accelerator down. This is why it’s better to use the Controller to handle input than the pawn. You can separate things such as “Walk” and “Accelerate Car” if your game ever needs to. You can technically use the Character/Pawn, but it’s often a cleaner approach to use the controller. But it comes down to personal preference.

I didn’t have time to watch the video on what they’re doing, but yes. Unless you have something (like say, physics!) stopping your character from moving after you let go. The velocity is just going to keep them moving. Usually you add a MovementComponent that handles all the physics, and you use the function inside that AddMovementInput() to move your pawn around. Also, it’s a good idea to do


void ACharacter::MoveRight(float Val)
{
if(Val == 0)
{
return;
}

//Your code here
}


This can just help performance.

Your mesh is your visual looks. Your capsule is your collision detection. They’re separate for both performance as well as accuracy. You CAN use a Mesh for collision, but it’s expensive and can lead to collision missing because it needs such fine precision it can often get missed or even stuck. Thus, most people use a Capsule for “walking” and “normal physics” type collisions, such as running into walls (no need for accuracy), and use the Mesh for “high-end” collision such as bullet hits. The mesh usually has a Physics Asset associated with this.

Your Collision and your Mesh are separate. But your Mesh doesn’t have physics applied to it. So that means your Collision is what’s standing on the ground, you just make it look like your Mesh is actually what’s doing it. So your mesh just needs to be moved down to fit the collision. You can move it in the editor, look at your transformation/translation widgets. Then in your C++ Constructor you can set the Mesh to follow those coordinates



ABLTPawn::ABLTPawn(const class FObjectInitializer& ObjectInitializer)
:Super(ObjectInitializer)
{
	if (GetMesh())
	{
		GetMesh()->RelativeLocation = FVector(0, 0, -44);
		GetMesh()->RelativeRotation = FRotator(0, -90, 0);
	}
}


Thank you very much for the reply. I’ll redo it with a controller, because it does seem like the better approach then.

Considering the MoveRight() method, you mean it is more effective considering Val == 0 more often than Val != 0, and then just return it, right? I think that makes good sense anyway.

Also, thank you for the GetMesh() portion, that’s nice to know! I’ll just stick to the capsule collision for now, until I am done writing, perhaps trivial, movement code . . . :slight_smile:

Again thank you for the reply, it really helped sorting my beginning problems out.

EDIT: Also figured why the Pawn in the UE4 Documentation stops. I feel a bit stupid now… I wrote it in a much more ineffective way, where the velocity was only updated whenever the value was different from zero. It will never return to zero then. I then wrote the position was to be updated with the vector every tick, which obviously makes it go on forever without any possibility stop. It could only be changed to move the opposite direction.