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"

In UE4 C++, how do I snap two object faces together during runtime so they are flush with one another?,How do I create a constraint in UE4 such that the bodies are projected together?

Okay, so I am trying to create a simple self-reconfigurable robotic simulator in UE4. I have the distributed control, message passing, etc. working, but I am somewhat stuck on the dynamic constraints. I have written a self-reconfigurable simulator using OpenGL, PhysX, and OpenFrameworks, but I would love to implement this in UE4 to take advantage of its vast array of features (drag and drop, easy environment creation, etc.).

I have a lot of experience with using PhysX directly, and I can use PhysX directly in my other simulator to create fixed joints that "pull" the constrained components together automatically. PhysX does this automatically using low level flags and appropriate relative positions/orientations of the bodies to be constrained. I am trying to achieve something similar in UE4.alt text

I am attaching a picture of the situation I have and what I would like to have after the correction. I have two robotic modules (in the simplest case) that need to dock together during runtimealt text. These are autonomous robots, so it is impossible that they will ever line their docks up exactly such that there is zero error. I am able to spawn a physics constraint (fixed joint) to hold them together and weld them together, but the difference in position and orientation remains, even when the constraint is applied. They are simply stuck together as shown in the picture. (Note that the error in this picture is exaggerated. It is not usually this much.) This is problematic, because we have physical mechanisms on the real hardware that guide the docks into the correct place. So, I need to fix the position and orientation error during runtime to "dock" the modules together flush.

My question is whether or not anyone knows if something similar can be achieved in UE4? I read about collision bounds and overlaps and didn't know if maybe I could detect an overlap at a certain tolerance and use that somehow. I could manually move the modules, but, in general, each side could have more modules connected, meaning all of them would have to be relocated and reoriented, which would be quite tedious. I didn't know if anyone else knew of a simpler way to handle this?

Any help would be appreciated.

Best,

TJ

Product Version: Not Selected
Tags:
more ▼

asked Sep 17 '15 at 08:41 PM in C++ Programming

avatar image

tjcollins47
11 3 4 4

avatar image rantrod Sep 17 '15 at 09:13 PM

If the pieces are supposed to rigidly attach to each other and then act as one, I would look into "AttachTo" rather than using a physics constraint. Example using blueprints: https://answers.unrealengine.com/questions/257340/attach-actor-to-another-actor-based-on-socket-poin.html. Docs on C++: https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/Components/USceneComponent/AttachTo/index.html.

avatar image tjcollins47 Sep 17 '15 at 11:34 PM

Thanks for your help! How do I give you credit for the answer?

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

2 answers: sort voted first

Ok, so based on rantrod's help, the following code worked. In summary, I had to use AttachRootComponentTo in order to line up the docks, then I used a physics constraint actor to actually make the connection. It should be enough to weld the elements together once they are lined up, but that part I still can't get to work. Thanks!:

         connections[modules[0]->GetIDNumber()][BACK_DOCK] = modules[1]->GetDocks()[FRONT_DOCK];
         connections[modules[1]->GetIDNumber()][FRONT_DOCK] = modules[0]->GetDocks()[BACK_DOCK];
         modules[0]->SetDockEngaged(BACK_DOCK, true);
         modules[1]->SetDockEngaged(FRONT_DOCK, true);
         modules[0]->AttachRootComponentTo(modules[1]->GetRootComponent(),"",EAttachLocation::SnapToTarget, true);
         modules[0]->GetRootComponent()->SetRelativeRotation(FRotator(0,0,0));
         modules[0]->GetRootComponent()->SetRelativeLocation(FVector(0,0,190));
         modules[0]->WeldDockToComponent(BACK_DOCK, modules[1]->GetDockComponent(FRONT_DOCK));
         APhysicsConstraintActor *a = GetWorld()->SpawnActor<APhysicsConstraintActor>();
          a->GetConstraintComp()->SetConstrainedComponents(modules[0]->GetSlaveOuterMesh(), "BackDock", modules[1]->GetMasterOuterMesh(), "FrontDock");
          a->GetConstraintComp()->SetLinearXLimit(ELinearConstraintMotion::LCM_Locked, 0);
          a->GetConstraintComp()->SetLinearYLimit(ELinearConstraintMotion::LCM_Locked, 0);
          a->GetConstraintComp()->SetLinearZLimit(ELinearConstraintMotion::LCM_Locked, 0);
          a->GetConstraintComp()->SetAngularSwing1Limit(EAngularConstraintMotion::ACM_Locked, 0);
          a->GetConstraintComp()->SetAngularSwing2Limit(EAngularConstraintMotion::ACM_Locked, 0);
          a->GetConstraintComp()->SetAngularTwistLimit(EAngularConstraintMotion::ACM_Locked, 0);



more ▼

answered Sep 17 '15 at 11:33 PM

avatar image

tjcollins47
11 3 4 4

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

I'll repost my answer her for credit :)

If the pieces are supposed to rigidly attach to each other and then act as one, I would look into "AttachTo" rather than using a physics constraint. Example using blueprints: https://answers.unrealengine.com/questions/257340/attach-actor-to-another-actor-based-on-socket-poin.html. Docs on C++: https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/Components/USceneComponent/AttachTo/index.html.

more ▼

answered Sep 18 '15 at 12:27 AM

avatar image

rantrod
1.5k 49 47 216

(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