0
\$\begingroup\$

I'm newbie in Unreal development and I don't know how to move my pawn faster.

By the way, I'm using Unreal 4.16.

I'm developing Pong game and I have this method to move the pawn:

void AAIPaddle::MovePaddle(float Scale)
{
    // Add a movement input, hardcoding Z speed to 100.0f
    FVector direction = FVector(0.0f, 0.0f, 100.0f);

    // Scale could be -1.0f or 1.0f or 0.0f.
    AddMovementInput(direction, Scale);
    if (OurMovementComponent &&
        (OurMovementComponent->UpdatedComponent == RootComponent))
    {
        OurMovementComponent->AddInputVector(direction * Scale);
        ZVelocity = Scale;
    }
}

You can find the class AAIPaddle here.

I use this FVector direction = FVector(0.0f, 0.0f, 100.0f); to set its speed, but I change the value 100.0f with 400.0f or another greater values and it moves with the same speed.

Maybe I haven't understood anything. How can I change its movement speed?

I'm using the following class that inherits from UPawnMovementComponent.

void UPaddlePawnMovementComponent::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction)
{
    Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

    // Make sure that everything is still valid, and that we are allowed to move.
    //      PawnOwner: which pawn owns this MovementComponent.
    //      UpdatedComponent: the component we move and update.
    //      ShouldSkipUpdate: Possibly skip update if moved component is not rendered or can't move.
    // If none own this component or there isn't anything to move or we have to skip this update, then return.
    if (!PawnOwner || !UpdatedComponent || ShouldSkipUpdate(DeltaTime))
    {
        return;
    }

    // Get (and then clear) the movement vector that we set in ACollidingPawn::Tick
    FVector DesiredMovementThisFrame = ConsumeInputVector().GetClampedToMaxSize(1.0f) * DeltaTime * 150.0f;
    // If movement isn't nearly zero
    if (!DesiredMovementThisFrame.IsNearlyZero())
    {
        FHitResult Hit;
        // Move our UpdatedComponent by the given DesiredMovementThisFrame, and sets rotation to
        // UpdatedComponent->GetComponentRotation(), do a bSweep and store any hit on Hit.
        SafeMoveUpdatedComponent(DesiredMovementThisFrame, UpdatedComponent->GetComponentRotation(), true, Hit);

        // If we bumped into something, try to slide along it
        if (Hit.IsValidBlockingHit())
        {
            StopMovementImmediately();
        }
    }
};

The project is public in Github.

Maybe I don't understand something about Vectors.

\$\endgroup\$
  • \$\begingroup\$ GetClampedToMaxSize(1.0f) this is limiting the max size of the vector(aka velocity)and that is why you can't make it faster. \$\endgroup\$ – Westside Tony Jun 9 '17 at 9:53
0
\$\begingroup\$

I agree with Westside Tony that GetClampedToMaxSize(1.0f) is limiting the max size of the vector,

you can easily test this by increasing that number for example instead of

FVector DesiredMovementThisFrame = ConsumeInputVector().GetClampedToMaxSize(1.0f) * DeltaTime * 150.0f;

you can try

FVector DesiredMovementThisFrame = ConsumeInputVector().GetClampedToMaxSize(200.0f) * DeltaTime * 150.0f;

or you can manually scale using

FVector DesiredMovementThisFrame = ConsumeInputVector().GetClampedToMaxSize(1.0f) * DeltaTime * 600.0f;

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.