x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.

Product Version: Not Selected
Tags:
more ▼

asked Feb 10 '15 at 06:02 PM in C++ Programming

avatar image

Karner
90 9 10 20

avatar image spazchicken Feb 10 '15 at 06:28 PM

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?

avatar image Karner Feb 10 '15 at 06:36 PM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

I created a component and set it to the door's halfway point. I then did what I said in reply to Mike'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 Mike for making me realise my error.

more ▼

answered Feb 10 '15 at 07:07 PM

avatar image

Karner
90 9 10 20

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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.

more ▼

answered Feb 10 '15 at 06:27 PM

avatar image

mikepurvis
2.5k 102 67 261

avatar image Karner Feb 10 '15 at 06:35 PM

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

alt text

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.

alt text

pic.png (29.8 kB)
avatar image mikepurvis Feb 10 '15 at 06:58 PM

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.

avatar image Karner Feb 10 '15 at 06:59 PM

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?

avatar image mikepurvis Feb 10 '15 at 07:22 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question