I was following the Player Input and Pawns tutorial on the documentation. So, in the ‘On Your Own’ section, there was a challenge that if the player was moving, and he pressed Spacebar then the cube would instantly become double the size.
I decided to do it by making a boolean true if the movement keys were pressed. Apparently, there are no Axis Mapping Pressed functions so I had to make duplicate Action Mappings. What would be a better way?
I also wanted to implement that the speed of the object would increase the longer the key was pressed. I am doing it like this -
TimeXW = PController->GetInputKeyTimeDown(EKeys::W);
TimeXS = PController->GetInputKeyTimeDown(EKeys::S);
if (TimeXW != 0.0f)
{
CurrentVelocity.X = FMath::Clamp(AxisValue, -1.0f, 1.0f) * 100.0f * TimeXW;
TimeXW = 0.0f;
}
else if (TimeXS != 0.0f)
{
CurrentVelocity.X = FMath::Clamp(AxisValue, -1.0f, 1.0f) * 100.0f * TimeXS;
TimeXS = 0.0f;
}
Is there a better way? Also, what does the word ‘EKeys’ in GetInputKeyTimeDown mean?
When I added this acceleration-time stuff, the object would continue moving even when I released the key. Why is this happening now but not before?
I fixed it by setting the CurrentVelocity to zero every tick after setting the new location. No idea why I had to do this now.
if (!CurrentVelocity.IsZero())
{
FVector NewLocation = GetActorLocation() + (CurrentVelocity * DeltaTime);
SetActorLocation(NewLocation);
CurrentVelocity.X = 0.0f;
CurrentVelocity.Y = 0.0f;
}
Thanks In advance!