Question about sweep when calling AddActorWorldOffset() on a platform

I noticed that when I enable sweep on my moving platform, it jitters when I step on it (or stops entirely if it’s moving up).

I feel like I should enable sweep, since it’s colliding with the player, but it seems to break the wanted behavior.

What’s going here?

This shouldn’t happen. Without seeing any code however, I cannot assist. Will you share the code using the < / > toolbar icon (not screenshot please) and I shall take a look

Hi beegeedee, thanks for replying!

This is happening on the server. I tested it again. When standing on the platform, it will move down, but not up, if sweep is enabled. If it’s disabled, this doesn’t happen.

I also checked the object’s details in the editor and it has Simulate Physics disabled.

Here’s the code:

AMovingPlatform::AMovingPlatform(void)
{
	PrimaryActorTick.bCanEverTick = true;
	SetMobility(EComponentMobility::Movable);

	bReplicates = true;
	SetReplicatingMovement(true);
}

void AMovingPlatform::BeginPlay()
{
	Super::BeginPlay();

	StartLocation = GetActorLocation();
	TargetLocation = GetTransform().TransformPosition(DestinationOffset);
	MoveDistance = (TargetLocation - StartLocation).Length();
}

void AMovingPlatform::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	if (HasAuthority()) 
	{
		MovePlatform(DeltaTime);
	}
}

void AMovingPlatform::MovePlatform(float DeltaTime)
{
    // Setting sweep to false (or default value) fixes the issue
	AddActorWorldOffset((TargetLocation - StartLocation) * DeltaTime / MoveSpeedSeconds, false);

	if (FVector::Distance(GetActorLocation(), StartLocation) > MoveDistance)
	{
		UpdateMoveTarget();
	}
}

void AMovingPlatform::UpdateMoveTarget()
{
	SetActorLocation(TargetLocation);

	FVector TempVector = TargetLocation;
	TargetLocation = StartLocation;
	StartLocation = TempVector;
}

Have you checked against the end of lecture code.?

Privacy & Terms