# \[C++/VR\] Prevent clipping on pick up object

**URL:** <https://forums.unrealengine.com/t/c-vr-prevent-clipping-on-pick-up-object/439172>\
**Category:** XR Development\
**Tags:** physics-constraint, clipping, pickup, unreal-engine, question, CPP\
**Created:** [December 9, 2018, 3:59pm UTC](https://forums.unrealengine.com/t/c-vr-prevent-clipping-on-pick-up-object/439172 "2018-12-09T15:59:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_385d7281](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_385d7281](https://forums.unrealengine.com/u/anonymous_user_385d7281)\
**Post date:** [December 9, 2018, 3:59pm UTC](https://forums.unrealengine.com/t/c-vr-prevent-clipping-on-pick-up-object/439172/1 "2018-12-09T15:59:50Z")

</div>

As I understand it, physics constraints are the ideal way to attach a pick-up to a VR controller (Actor) while retaining the inability for the player to make the picked up object from clipping through walls. However when I try to set a constraint to the controller actor, the mesh will not move at all with the controller.

Current code/setup is as follows:

AStaticMeshActor with UPhysicsConstraintComponent and PickUpAble Tag

AVRController Class derived from AActor

I have tried reversing the Actors in the SetConstrainedComponents and the behavior is the same.

```
void AVRController::Grab()
{
if (m_b_can_pick_up == true)
{
	if (m_pick_up_actor != nullptr)
	{
	// Works but clips thorough objects. See below video
	//m_pick_up_actor->GetStaticMeshComponent()->SetSimulatePhysics(false);
	//m_pick_up_actor->K2_AttachToActor(this, TEXT("Trigger"), EAttachmentRule::KeepWorld, EAttachmentRule::KeepWorld, EAttachmentRule::KeepWorld, false);

	UPrimitiveComponent* pick_up_actor_cast = Cast<UPrimitiveComponent>(m_pick_up_actor);
	m_pick_up_actor->m_phys_constraint->SetConstrainedComponents(m_vr_controller_mesh, NAME_None, pick_up_actor_cast, NAME_None);
	}
}
}

```

Here is a video of the not desired output

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/4/7/8476c86cb5a126edff95ac1f84d5a739d16256b7.jpeg "VR Clipping") ](https://www.youtube.com/watch?v=0bwknAvh-Us)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_385d7281](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_385d7281](https://forums.unrealengine.com/u/anonymous_user_385d7281)\
**Post date:** [December 10, 2018, 8:14am UTC](https://forums.unrealengine.com/t/c-vr-prevent-clipping-on-pick-up-object/439172/2 "2018-12-10T08:14:35Z")

</div>

After a day of testing and looking at other people’s code I was able to get the desired effect.

I needed to constrain the two static meshes with  
m\_pick\_up\_actor-\>m\_phys\_constraint-\>SetConstrainedComponents(m\_vr\_controller\_mesh, NAME\_None, m\_pick\_up\_actor-\>GetStaticMeshComponent(), NAME\_None);

I also had to set the following properties on the constraint  
Stiffness 5000  
Damping 500  
Contact 10  
LinearBreakThreshold 5000000

I also had to disable and enable the LinearBreakThreshold when teleporting.  
Here is a video of how it looks

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/8/a/88abf959a5711c348b9f1ef61c94039208937b6e.jpeg "VR PickUp Physics Constraint") ](https://www.youtube.com/watch?v=-YQaTvI5LOY)

---

<div class="post-metadata">

**Author:** ![ellishawn](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ellishawn](https://forums.unrealengine.com/u/ellishawn)\
**Post date:** [January 25, 2019, 9:58pm UTC](https://forums.unrealengine.com/t/c-vr-prevent-clipping-on-pick-up-object/439172/3 "2019-01-25T21:58:07Z")

</div>

Can you post a code snippet of that? I don’t see how you set those parameters on the constraint. Is that the constraintInstance? I don’t see those parameters on the contraintinstance either…
