Download

Constraint Components in C++

Unfortunaly, Rama’s WIKI article is the only “documentation” about constraint components in C++.

I copied the code from his wiki-page that should set up a new constraint-component connection between two actors.

So, I implemented it and set all the Linear and Angular Motions to locked. But it does nothing. I spawn the first object on a cliff and try to connect the second object, but instead of connecting to the first object it just falls to the ground.

All the functions are called with the right actors and I didn’t change anything in the code-example except the function-values for setting the motion-values.

The Actors have SetSimulatePhysics = true.

here is my code:



FConstraintInstance constraintInstance;
	FConstraintConnectionGenerator gen;
	constraintInstance = gen.getInstanceFor(base.parentElement->getElementType(), target.parentElement->getElementType()); // Gets the "right" values for specific types of objects
	StaticUtilityLibrary::CreateNewPhysicsConstraintBetween(base.parentElement, target.parentElement, constraintInstance); //Ramas functionality in a static class
}

FConstraintInstance FConstraintConnectionGenerator::getInstanceFor(EBotElementType base, EBotElementType target){
	FConstraintInstance inst;
	if (base == BET_ROD){


         /************************************ THIS IS CALLED IN MY TEST ***************************** /
		StaticUtilityLibrary::SetLinearLimits(inst, false, 2, 2, 2, 2);
		StaticUtilityLibrary::SetAngularLimits( //or make functions below non static, put in .h
			inst,
			2, //locked
			2, //swing 2 locked
			2, //twist is locked
			0, //swing 1 angle limit
			0, //swing 2 angle limit
			0 //twist locked
			);
	}

	return inst;
}

Am I missing something, or did something change or what am I doing wrong? :frowning:

Thanks for your help.

Okay, I got it. I just switched the actors in the function. I don’t know why that worked since the documentation says that Actor1 is the Root, but however… It Works… :slight_smile:

Well, aparently not really resolved.

I have really strange behaviours. The constraint only works every now and then. Even when I repeat the steps 1:1, sometimes it works, sometimes it doesnt work… I spawn always the same objects, the correct object pointers are always submitted to the function… I don’t know whats going on. Sometimes the objects spawn but behave like they do not have a constraint and fall to the ground… after 10 trys or so, sometimes it suddenly works…