Understanding Input Vector effect

Hi! Can someone help me understand input vectors - I get the idea that I can convert user inputs to vectors and keep adding them, they will accumulate and then will gradually decay, creating a nice smooth movement.

But I don’t understand the ratio between provided input vector and actual traveled distance.
E.g. think a very simple blueprint, that all it does is adds input vector for default pawn’s movement ocmponent for the first tick - Event TickDo N 1AddInputVector(0,0,100).
Given the base pawn position is (0,0,0), the question is - for how many ticks movement will last and what would be the final position?

So… Input vectors are not normalized but they are in the -1 to 1 range from any of the input systems. No (0,0,100)is possible.

When you interact with your input system those inputs are accumulated and they dissipate as soon as they are read/used.

The most common (and simple) formula used in various games is Input * speed * DeltaTime = displacement

The movement is controlled by the movement controller and it depends on its internal workings.

Character movement component for example can use acceleration. In this case the input might be taken as the position of the gas pedal in a car (0 is no gas 1 is floored) so the formula would be something in the lines of:

acceleration = (Input - decay) * DeltaSeconds;
speed += acceleration * DeltaSeconds;
displacement = speed * DeltaSeconds;

This is how the things work in very broad strokes. Opening the code for your movement component might give you more insight but keep in mind that it is a bit of a mess in there. Movement components have too many responsibilities (network prediction, correction, animations, physics, collisions).

This is a code piece from “FlyingMode.cpp” for example:

FProposedMove ProposedMove = Params.ProposedMove;
. . .
FVector MoveDelta = ProposedMove.LinearVelocity * DeltaSeconds;
. . .
UMovementUtils::TrySafeMoveUpdatedComponent(Params.MovingComps, MoveDelta, TargetOrientQuat, true, Hit, ETeleportType::None, MoveRecord);
1 Like

Thank you, I went investigating FloatingPawnMovement component and it roughly does the same thing with simple velocity based on input vector + acceleration and then converts velocity to delta.

And when it’s retrieving the input vector, it clamps it at size of 1.

image

Now it all makes sense.

The part that confused me originally is that AddMovementInput has two parts for the input vector - World Direction and Scale Value. Typically direction means that vector is already normalized and scale usually means it’s magnitude, but I guess in this case it’s probably used to either dampen vector a bit or to reverse the direction.