Move Another Actor (Push/Pull) With Component

I am trying to move an actor using a custom Component on my Character. The following code is reduced to parts necessary to understand my problem.

If my character stands in front of an object, MyComponent will identify it as MyObject. If the player moves forward, the value will be transmitted to the component:

void AMyCharacter::MoveForward(float Value)
{
	MyComponent->MovementValue = Value;
	const FVector Direction = GetActorForwardVector();
	AddMovementInput(Direction, Value);
}

The idea is that MyComponent will now move the object according to the player’s speed:

void UMyComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
	ACharacter* Owner = Cast<ACharacter>(GetOwner());
	float WalkSpeed = Owner->GetVelocity().Size();
	FVector MovementVector = Owner->GetActorForwardVector() * MovementValue * WalkSpeed;
	FVector StartVector = MyObject->GetActorLocation();
	FVector EndVector = StartVector + MovementVector * DeltaTime;
	MyObject->SetActorLocation(EndVector);
}

The problem now is, that if my character stands right in front of the object, the character can’t move because the object blocks its way. The velocity is zero and therefore the object does not move. However, after I run backwards ( bOrientRotationToMovement is false), it is possible to run. If I then run forwards again, the object will move.I found out that moving backwards will bring distance between my character and the object that allows the character to move. The distance becomes larger every time I start and end backwards movement. More precise: The distance between the character and the object changes every time movement has ended (or started?).

After walking backwards, it only takes a few times walking forward to close the distance and make it impossible to initiate another forward movement again.

Can someone help me with this?

Have you tried to disable collision on the object as soon as you register the object in front of the character so it cannot block your character from moving? Then if your character moves towards the object, it should move with the character. But you still need to determine how you will unregister the connection between the object and the character. Probably when the input button is released while the connection persists.

An alternative might be to attach the object to your character as soon as you get forward input while there is a registered object in front of the character. Then detach the object as soon as input is released. You could even slow the character speed as soon as the object is attached and reset to normal after the object is detached. When using attach, to ensure that the object never changes its position relative to the character, simply tell it to attach using the “keep world” vector parameters.

Fore warning, I didn’t try this so I’m not entirely sure if it will give you the result you’re looking for.

It feels a bit hacky and I don’t know if this will lead to future problems, but changing the object collision does work. After ignoring Pawns, the character can move forward with full speed. What is more concerning to me is the fact that the distance between character and object changes. If I make a lot of small steps forward, the character ends up standing in the middle of the object. I think this is because AddMovementInput is not in sync with the component’s Tick, but I wouldn’t like moving MoveForward to Tick at all.

I’m still curious how to solve this. Attaching the object to the character is a nice idea, though. If I can’t figure it out what’s going on, I will make use of this approach. Thank you so far.

You may want to play around with setting the position of the object relative to the character while its being moved rather than adding movement to it and the character at the same time.

edit: (this might be what your’re already doing.)