Align 2 components to have the opposite rotations and the same location (C++)

I’m trying to align 2 actors using two of their components but cannot seem to get them to align properly at all. I’ve gotten the rotation to work so that they are facing eachother but cannot get the math right to get their position the same.

I’m spawning two actors at 0, 0, 0 with a rotation of 0, 0, 0 and I want component A to be at the same location as component B but with an inversed rotation.

How can I simply achieve this? I’ve tried using FTransforms, setting locations using offsets and such but cannot get the math right, can anyone help? Here is my code:

float angDif = (getOppositeAngle(exitRot) - entRot);
nextRoom->SetActorRotation(FRotator(0.0f, angDif, 0.0f));

/** Rooms now share opposite rotations, as plannned **/

//nextRoom->SetActorLocation((exitLoc + connection->GetRelativeTransform().GetLocation()) + connection->GetDoorwayHalfWidthVector());
//GEngine->AddOnScreenDebugMessage(-1, 50.0f, FColor::White, nextRoom->GetActorLocation().ToString());
//nextRoom->SetActorLocation(exitLoc - (entLoc - nextRoomLoc));

//nextRoomLoc = nextRoom->GetActorLocation() + bOffset;
//nextRoom->SetActorLocation(nextRoomLoc);
FVector connectionOffset = connection->GetRelativeTransform().GetLocation();
connection->SetRelativeLocation(roomExits[i]->GetComponentLocation());
FVector exitOffset = connection->GetRelativeTransform().GetLocation();
nextRoom->SetActorLocation(connectionOffset + exitOffset);
connection->SetRelativeLocation(connectionOffset);

As you can see, I’ve tried many equations but cannot find one that works. Any help would be greatly appreciated.

Just to make sure, you are wanting one to go clockwise and another counter clockwise? Are you controlling them or is this a fixed animation?

Hi,

What behavior are you seeing?

I needed to align 2 actors on the same location with the opposite rotation for the purpose of then playing an animation on both that was synced, an attack and defend sequence. What was happening is the collision was preventing the location from being set correctly, if allowed a sweep on the set actor location it would be in a random point bumping up against the collision capsule. If I did not allow sweep, or tried to teleport the actor would disappear.

The solution for me was to turn off collision on the actor just before setting it to the same location of the other one. No math was needed for the location, and a simple inverse for the rotation only such as what you are doing.

There’s no animations. Please see the picture below:

29561-pic.png

Door A of Room B needs to connect to Door B of Room A. The issue is making the doorways themselves line up correctly. I’m getting results where they’re offset, or in completely wrong locations.

Hey spazchicken, please check my reply to 's comment.

That doesn’t look like a collision issue, just the offsets. Have you tried debugging to see what the numbers you are getting look like? That may help get through the stickiness of figuring it out. I haven’t used the relative location much, I’ve done everything with the world location.

If I get the world location of Room B’s doorway and Room B’s origin I should have B’s offset and then be able to add the offset to Room A’s doorway to get Room B’s final position, right?

I created a component and set it to the door’s halfway point. I then did what I said in reply to 's comment:

If I get the world location of Room B’s doorway and Room B’s origin I should have B’s offset and then be able to add the offset to Room A’s doorway to get Room B’s final position, right?

Once I had done that I tested it with multiple rotations and locations and all seem to be working so far. Thanks for making me realise my error.

That would be correct if the dimensions of the room were the same, but think it’s missing a piece here because they are shaped different. The point around which it’s rotating also may be effecting it.