I have some questions about the AddMovementInput function and movement in general
It feels more natural to me to work with character movement in terms of vector math, manipulating position, velocity, and acceleration. I am unsure of what exactly AddMovementInput is doing under the hood. Is it just adding velocity ?
I replaced the AddMovementInput node in the side scroller example with vector math nodes to set the velocity as shown in the attached image. It works but my character is no longer turning to match the direction of movement, the “orient rotation to movement” option seems to be broken by adding velocity in this manner.
- Is this an ill-conceived way to control character movement ?
- Am I also breaking other things i have not discovered yet by doing this?
- What precisely does the AddMovementInput function do?
- what is the best way to manipulate the position, velocity, and acceleration of characters (and actors in general if different methodologies are required)
The movement input vector describe the player’s intention. For example, an InputVector of (1, 0, 0) means that the character wants to move in the world X-direction. The accumulated input is processed by the movement component every tick, where it converts the input to update the velocity, adhering to constraints like maximum speed, constrained planes and such. CharacterMovementComponent scales the InputVector so (1, 0, 0) or (3, 0, 0) results in the same.
Now, I have used setting the Velocity directly to move the character instead of MovementInputVectors and it seems to work fine. If you want to do things like applying the acceleration and making sure the velocity is within some limits, go ahead!
Things to take into account though, if you are working on a multiplayer game:
- Velocity is not replicated, so you must replicate it yourself from server to client one way or the other. Clients would have to send their inputs and the server would have to replicate the resulting velocity to all clients.
- On the other hand, AddMovementInput is already set up to send to the server. In other words: you can call AddMovementInput on a client and its effect will show on the server (and thus all other clients).