How to make a player move (WASD)?

First of all, let me start by saying I am very new. New as in about 5 days of using Unreal. I just switched from Unity hoping Unreal would be better. But I have no idea how to make my player move when pressing, W, A, S or D. I want to make a controller script that takes mouse/keyboard input and everything in between. So how can I extend the player controller class?

-Edit-

Let me also say I have no idea how to remove the existing movement component, wherever that may be… I opened the game up and I see a game where I can move around, but it’s more like floating. I don’t like it. I want to remove it but I don’t know how to.

Welcome to the Unreal Community… You will love it! Great engine…

I’ve re-read your post above and I’m not sure I understand the question. Could you define what you are attempting here? Thanks!

teak

Hey

Sorry for the late response. I was just falling asleep when I got your notification!

Anyways, what I am trying to say is I’m confused as to how to program my player to move based on WASD input. I opened a blank C++ project and for some reason my player is moving around (which by the way I have no idea why it does since I didn’t do anything yet) but I want to make the movement different. Also another factor contributing to this confusion is that I am new to C++ as well. Additionally, I assume I’m going to have to remove whatever component is causing the unwanted movement, but unfortunately I don’t know where it is. If you could guide me to fix this problem, that would be amazing thanks!

Edit

Also I think what I’m mainly stuck on in scripting:

  1. How to check for hardware input?
  2. How to move an object

No one knows how to make the player move?

I don’t recommend removing the movement component, as it handles a lot of functionality that you would otherwise have to create yourself, and I don’t think it is all that related to the problems you are experiencing with movement in general. You also don’t really need to extend the playercontroller (at least not for movement) as long as you are using a character class derivative for your pawn.

Anyways, the functionality for the character movement can be found within your character class, which should have been created automatically if you started a project based on a template (character). If you didn’t start a template, I highly recommend that you do. Once you get used to the UE4 environment, you can always dive into a blank C++ project. For templates, the movement related functionality can be found in the MoveRight and MoveUp functions. The functionality used for movement is likely something along the line of AddMovementInput(Direction vector, move value); what this function does is adding to the player acceleration, based in the direction value.

As for a quick rundown of the Unreal structure:

-You don’t really need to use a player controller. The character class takes care of pretty much everything. Playercontroller would only be kinda necessary for HUD related functionality. That’s the only time I have found a use for it anyway.

-Movement component takes care of things like player velocity and has a plethora of built in functionality like jumping, crouching and whatnot. If you select the movement component in the blueprint version of your character, you can change a large amount of variable regarding movement, like jump height, max movement speed, acceleration, the gravity of your jumps, and so on.

-Input component takes care of your input. You can set up input in the project settings (which can be found in the editor) or the .ini file. Not sure of the exact name of the latter, since I generally just use the project settings. The input functions in your c++ files take the same name as the names you entered in the input settings. For default projects, a few inputs have already been added, those being (at least) MoveRight, MoveUp and Jump. There are two kinds of input; axis and action. Axis gives you a constant value between -1 and 1 (used for, for instance, analog stick input). Action gives you singular inputs, but enable you to bind functions to both the Onpressed and Onreleased state of the buttons.

-There are a variety of ways to make the player move.

  1. If you wish to use the velocity, using the aforementioned “AddInput” function will be your best bet. Just calculate your direction vector and add in your value (which is generally just the value you get from the axis input function).

  2. If you wish to directly set the location directly, the function SetActorLocation is your best bet. This one just takes a vector of the new location.

  3. A thing to keep in mind while moving your character around is his Movement Mode (a variable found within the Movement component). By default a character cannot just float up in the sky, meaning you can set the Z-value as much as you want, but if there’s nothing but air there, the character simply won’t move up (physics). If you wish to move your character in any direction you want, you must first set the movement mode to PHYS_Flying, which allows the character to move anywhere (but is extremely floaty in terms of movement).

It’s not the best rundown, but I hope this helps a bit towards getting your character to move.

Hello ,

What I am confused mostly about is every time there is an issue with Unreal and I manage to find a solution, it just causes more problems. I used to use Unity and there was never issues like this. The only valid reason I have for manually programming player movement is because I want to learn C++. Anyways, I’ll try all the ideas you mentioned and get back to you if I have trouble. Thanks!

Hey ,

I see all these tabs in the details tab labeled “Physics”, “Input”, etc. Are those my components? How can I delete them? It doesn’t let me.

Here is a picture of said tabs:

Also, I see an add component button but when I click on it I don’t see any input component or anything you mentioned, even my script isn’t there. I seriously don’t understand Unreal and I would appreciate if some things were cleared up. Thanks :slight_smile:

The reason the player is moving weird is because it is using the default movement. You need to create a new game mode blueprint, and set its player to your new player.