Collision fix not working

After utilising the sweep stuff defined in this post:

Still seeing janky collisions and not sure why … perhaps I’ve misunderstood. Any thoughts?

// Called every frame
void AMovingPlatform::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	// if stationary there is no movement necessary
	if ( MaxDistance == 0.0 )
		return;
	
	FVector const NewLocation = GetActorLocation() + (PlatformVelocity*DeltaTime);
	FHitResult Hit;
	SetActorLocation(NewLocation, true, &Hit);

	if ( Hit.GetActor() )
	{
		UpdatePushedLocation(Hit);
		SetActorLocation(NewLocation);
	}
		
	
	DistanceMoved = FVector::Dist(AnchorLocation,NewLocation);
	if ( DistanceMoved > MaxDistance )
	{
		// We are moving the new anchor to be the start + *exactly* the max distance to guarantee Dist() is 0
		AnchorLocation = AnchorLocation + ( PlatformVelocity.GetSafeNormal() * MaxDistance );
		SetActorLocation(AnchorLocation);
		PlatformVelocity = -PlatformVelocity;		
	}
}

// updates the item that there is overlap with
void AMovingPlatform::UpdatePushedLocation(const FHitResult& HitResult )
{
	const double Distance = FVector::Dist(HitResult.TraceStart, HitResult.TraceEnd);
	const FVector Direction = PlatformVelocity.GetSafeNormal();
	const FVector Delta = Direction * Distance;
	HitResult.GetActor()->AddActorWorldOffset(Delta);	
}```

I found something in the comment in the lesson titled “DO NOT use EventTick …”.

The NB regarding sweep only occurring on the root component is spot on.

image

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms