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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Physics constrain to Axis in c++

How can I constrain physics to one axis in c++?

Product Version: Not Selected
more ▼

asked Apr 05 '14 at 08:33 PM in C++ Programming

avatar image

172 14 19 112

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

1 answer: sort voted first


There is a huge set of properties called FConstraintInstance

You can limit or lock xyz movement axis using this!

Here is my helper function to set these properties


 FORCEINLINE void SetLinearLimits(
         FConstraintInstance& Constraint,
         bool bDisableCollision,
         const uint8& XLim, const uint8& YLim, const uint8& ZLim,
         const float& Size,
         bool SoftLimit=true,
         float SoftStiffness=0,
         float SoftDampening=0
         Constraint.bDisableCollision = bDisableCollision;
         switch (XLim)
             case 0 : Constraint.LinearXMotion = ELinearConstraintMotion::LCM_Free; break;
             case 1 : Constraint.LinearXMotion = ELinearConstraintMotion::LCM_Limited; break;
             case 2 : Constraint.LinearXMotion = ELinearConstraintMotion::LCM_Locked; break;
         switch (YLim)
             case 0 : Constraint.LinearYMotion = ELinearConstraintMotion::LCM_Free; break;
             case 1 : Constraint.LinearYMotion = ELinearConstraintMotion::LCM_Limited; break;
             case 2 : Constraint.LinearYMotion = ELinearConstraintMotion::LCM_Locked; break;
         switch (ZLim)
             case 0 : Constraint.LinearZMotion = ELinearConstraintMotion::LCM_Free; break;
             case 1 : Constraint.LinearZMotion = ELinearConstraintMotion::LCM_Limited; break;
             case 2 : Constraint.LinearZMotion = ELinearConstraintMotion::LCM_Locked; break;
         Constraint.LinearLimitSize = Size;
         if(SoftLimit) Constraint.bLinearLimitSoft = 1;
         else Constraint.bLinearLimitSoft = 0;
         Constraint.LinearLimitStiffness     = SoftStiffness;
         Constraint.LinearLimitDamping     = SoftDampening;


Spawning Contraint

 //in some actor class
 ConstraintComp = NewObject<UPhysicsConstraintComponent>(this);


Helper Function

 //helper function from the .h 
 //0,2,2 = object can only move along x axis


Init Constraint

 //~~~ Init Constraint ~~~
 ConstraintComp->SetConstrainedComponents(YourStaticMeshActor->StaticMeshComponent, NAME_None, YourStaticMeshActor2->StaticMeshComponent->StaticMeshComponent,NAME_None);

the above constraints two SMAs together

you could also use the UPrimitiveComponent of just about anything.

Note that the first supplied component will be the root, and the 2nd component is the one that is constrained in its movements in relation to the root.

more ▼

answered Apr 06 '14 at 12:14 AM

avatar image

10.6k 446 345 1088

avatar image slayeruk Apr 06 '14 at 12:10 PM

Thanks I will try it out.

(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