GetWorld()-> ComponentSweepMulti (...) ignore Rotation. Why? ((

GetWorld()->ComponentSweepMulti(…) ignore Rotation. Why?? ((

Hey-

How are you using ComponentSweepMulti? Is this inside of a character or actor class? Could you provide more information on what you’re trying to do and what exactly is happening?

Cheers

Hi! I create a door with “UStaticMeshComponent* StaticMeshDoorComponent”.

define
{
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = FlatDoor)
		UStaticMeshComponent* StaticMeshDoorComponent;
}

create
{
	StaticMeshDoorComponent =CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StaticMeshDoorComponent"));
	StaticMeshDoorComponent->SetSimulatePhysics(false);
	StaticMeshDoorComponent->AttachTo(RootComponent);
}

bug function. check collision of StaticMeshDoorComponent with all actors in the world. Door actor have FRotator(0.0f,0.0f,.0.0f) rotation.

bool AFlatDoor::SetDoorRotation(const FRotator& rotator, bool opening)
{
	FComponentQueryParams componentParams;
	componentParams.AddIgnoredActor(this);
	TArray<FHitResult> hits;

	if (!GetWorld()->ComponentSweepMulti(
		hits,
		StaticMeshDoorComponent,
		StaticMeshDoorComponent->GetComponentLocation() + FVector(0.0f, 0.0f, 1.0f),
		StaticMeshDoorComponent->GetComponentLocation() + FVector(0.0f, 0.0f, 2.0f),
		GetActorRotation()+rotator,
		componentParams)) 
	{
		StaticMeshDoorComponent->SetRelativeRotation(rotator);
		return true;
	}
	else
	{
		for (int i = 0; i < hits.Num(); i++)
		{
			DrawDebugPoint(GetWorld(), hits[i].ImpactPoint, 10.0f, FColor(255, 0, 0));
			DrawDebugPoint(GetWorld(), hits[i].Location + FVector(0.0f, 0.0f, 5.0f), 10.0f, FColor(0, 0, 255));
			GEngine->AddOnScreenDebugMessage(-1, -1.0f, FColor(0, 255, 0), hits[i].Actor->GetName());
		}

		return false;
	}
}

Collision “StaticMeshDoorComponent” with “bpObject69”. Result:

Hey-

It appears you’re trying to detect if something is blocking the door before it opens, correct? How is the function SetDoorRotation() being called? Also, what is the value of the rotator that is being passed into the function? Additionally, the start and end locations of the trace are along the Z-axis. This trace won’t detect something blocking the door along its opening path.

An alternative method you could use would be to use the door’s collision to check either an OnHit or OnOverlap event and if the event is triggered, then stop how the door is opening (if it’s an animation or you’re setting a new rotation).

Cheers

Door have states:

	enum E_STATE
	{
		ES_CLOSING,
		ES_CLOSED,
		ES_CLOSING_STOP,
		ES_OPENING,
		ES_OPENED,
		ES_OPENING_STOP,
	} state;

Tick function:

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

	if (state == ES_OPENING)
	{
		FRotator rotate = StaticMeshDoorComponent->GetRelativeTransform().GetRotation().Rotator();
		float localSpeed = DeltaTime*OPEN_ANGULAR_SPEED;

		if (fabsf(rotate.Yaw + localSpeed) >= fabsf(GetOpenAngle()))
		{
			if (SetDoorRotation(rotate + FRotator(0.0f, 0.0f, GetOpenAngle()), true))
				OpenNow();
			else
				state = ES_OPENING_STOP;
		}
		else
		{
			rotate.Yaw += (bLeftSided ? -localSpeed : localSpeed);

			if(!SetDoorRotation(rotate,true))
				state = ES_OPENING_STOP;
		}
	}
	else if (state == ES_CLOSING)
	{
		FRotator rotate = StaticMeshDoorComponent->GetRelativeTransform().GetRotation().Rotator();
		float localSpeed = DeltaTime*OPEN_ANGULAR_SPEED;

		if (fabsf(rotate.Yaw) <= localSpeed)
		{
			if (SetDoorRotation(FRotator(0.0f, 0.0f, 0.0f),false))
				CloseNow();
			else
				state = ES_CLOSING_STOP;
		}
		else
		{
			rotate.Yaw += (rotate.Yaw<0.0f ? localSpeed : -localSpeed);

			if(!SetDoorRotation(rotate,false))
				state = ES_CLOSING_STOP;
		}
	}
}

I eventually replaced “ComponentSweepMulti()” on “LineTraceMulti()” in function “SetDoorRotation()”.

Hey-

Were you able to get the behavior you were looking for by switching to using LineTraceMulti()? What exactly was the behavior you were looking for and what behavior did you have when using ComponentSweetMulti()? If you were able to solve the problem by using a different function would it be acceptable if I closed this post for tracking purposes?

Ok. Close it.