Download

What options do I have? Collision issues

Hello dear forums.

I’ve come a long way with my conveyor belt implementation, I did however come across a slight issue. To understand the issue, you must first understand the ongoing implementation.

This far, I only have one blueprint of a custom class: AConveyorBeltMaster inheriting for AActor. The definition is quite simple, since there’s only 3 component to the class:

  • UStaticMeshComponent (StaticMeshComponent)
  • USplineComponent (SplineComponent)
  • UBoxComponent (BoxCollisionComponent)

The static mesh is… well the static mesh. The spline component is the spline that I want my “moving parts” to follow along, and the box component is the collision box used to attach the “moving part” to the conveyor belt. The size of the box component is automatically calculated, based on the size of the static mesh component. This is done fairly simple:



void AConveyorBeltMaster::BeginPlay()
{
    FTransform ComponentBounds;
    FVector BoxExtent = StaticMeshComponent->CalcBounds(ComponentBounds).BoxExtent;

    BoxExtent.X -= 1.f;
    BoxExtent.Y -= 1.f;

    BoxColissionComponent->SetBoxExtent(BoxExtent);
    BoxCollisionComponent->SetRelativeLocation(FVector(0.f, 0,f BoxExtent.Z + 15));
}


I’ve created the logic to move a part along the spline component, by listening on the event OnBeginOverlap within my “moving parts” master class.



void AMovingPartMaster::OnBeginOverlap(/* arguments */)
{
    if (OtherActor->IsA(AConveyorBeltMaster::StaticClass()))
    {
        AConveyorBeltMaster* ConveyorBelt = Cast<AConveyorBeltMaster>(OtherActor);
        CurrentSplineToFollow = ConveyorBelt->SplineComponent;
        DistanceAlongSpline = 0.f;
        ShouldMove = true;
    }
}


Here’s the implementation of the tick:



void AMovingPartMaster::Tick(float DeltaTime)
{
    // If there is a current spline to follow
    if (CurrentSplineToFollow && ShouldMove)
    {
        float CurrentMovementSpeed = MovementSpeed * DeltaTime;
        DistanceAlongSpline = DistanceAlongSpline + MovementSpeed;

        FVector NewLocation = CurrentSplineToFollow->GetLocationAtDistanceAlongSpline(DistanceAlongSpline, ESplineCoordinateSpace::World);
        SetActorLocation(NewLocation);
    }
}


This works just as expected. The moving part overlaps the box collision of the conveyor belt, and begins to slide along the top of the conveyor belt. My issue however, is whenever the conveyor belt is facing another direction, meaning the moving part is not entering the conveyor belt from the “back”, the moving part starts behaving weirdly, as one would expect.

This is currently the outcome of the functionality as it is right now. giphy.gif

  • Red is direction
  • Green is spline component (individual by each conveyor belt)
  • Orange is moving part
  • Blue is conveyor belt

I’m very unsure of how to solve this issue, and I’m not sure what my options are.

I was hoping that some of you might shed some light on the issue, and guide me towards a solution that could work.

As far as I see there could potentially be two solutions:

  1. Make the moving part stop when it hits the “side” of the conveyor belt collision box (preferred)
  2. Make the moving part go towards the closest point of the spline component, and after that, move along the forward axis of the spline component

Is it possible for me to do any of these? If so, how? :slight_smile:

Is it colliding with 2 things simultaneously when it moves from the side?