C++ Pull Constraint

Hello!

I’m tinkering with constraints and I’d like to drag a ball around by a 1-link-chain.

I’m think that the way to do this is to create a constraint between my ball actor and a handle actor. I would then transform the handle actor around, and it would pull the ball around via the constraint.

I currently am getting no visible interaction between my handle and ball.

I’m using Rama’s tutorial on constraints (https://wiki.unrealengine.com/Physics_Constraints,_Create_New_Constraints_Dynamically_During_Runtime).

Here’s what I have so far to create the constraint:

//set up the constraint instance with all the desired values
	//
	FConstraintInstance ci;
	SetLinearLimits(ci, false, 0, 0, 0, 0);
	SetAngularLimits(ci, 0, 0, 0, 90, 90, 90);

	//New Object
	m_constraint_component = NewObject<UPhysicsConstraintComponent>(Mesh);
	if (!m_constraint_component)
	{
		//UE_LOG constraint UObject could not be created!
		return;
	}

	//~~~~~~~~~~~~~~~~~~~~~~~~
	//Set Constraint Instance!
	m_constraint_component->ConstraintInstance = ci;
	//~~~~~~~~~~~~~~~~~~~~~~~~

	//Attach to Root!
		m_constraint_component->AttachTo(Mesh, NAME_None, EAttachLocation::SnapToTarget);

	//~~~ Init Constraint ~~~
		m_constraint_component->SetConstrainedComponents(Mesh, NAME_None, m_constraint_target, NAME_None);

And here is how I’m moving the handle around:

	//Set World Location
	m_constraint_target->SetWorldLocation(location);

Any ideas/links?

I read this post (https://answers.unrealengine.com/questions/25182/physics-constrain-to-axis-in-c.html).

I believe it’s saying in the method SetConstrainedComponents(), my handle should come first, then my ball:

//~~~ Init Constraint ~~~
         m_constraint_component->SetConstrainedComponents(m_constraint_target, NAME_None,Mesh, NAME_None);

This still doesn’t show me any interaction.

However! If I don’t initialize my FConstraintInstance, the ball flops around lol. If I wanted no limits/locks on my constraint, how should I initialize it? 0’s don’t seem to do the trick.

Thats because you set everything to free. So it is basically no constraint. Set the zeros to 2. Better read ramas article again