# Remove Physics Constraints On Hit event

**URL:** <https://forums.unrealengine.com/t/remove-physics-constraints-on-hit-event/452814>\
**Category:** World Creation\
**Tags:** Constraints, physics-constraint, unreal-engine, Physics, CPP, question\
**Created:** [July 25, 2019, 12:28pm UTC](https://forums.unrealengine.com/t/remove-physics-constraints-on-hit-event/452814 "2019-07-25T12:28:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bionic\_Ape](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bionic_ape/32/1090124_2.png) [@Bionic\_Ape](https://forums.unrealengine.com/u/Bionic_Ape)\
**Post date:** [July 25, 2019, 12:28pm UTC](https://forums.unrealengine.com/t/remove-physics-constraints-on-hit-event/452814/1 "2019-07-25T12:28:55Z")

</div>

Hi,

I want to remove Physcis Constraints when a PrimitiveComponent is Hit.

I have a car with a constraint (e.g. X=0.0,Y=1.0,Z=0.0) and another car that is going perpendicular to the first one with a constraint of (X=1.0,Y=0.0,Z=0.0).

I remove the constraints OnHit event, but the physics simulation for that hit aren’t good. The force produced by the hit is not being simulated.

I’ve seen that this OnHit event is broadcasted by the Actor itself and not the PhysicsBody when it’s simulating.

How can I remove the constraints and keep the impulse given by the hit?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_935088b3](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_935088b3](https://forums.unrealengine.com/u/anonymous_user_935088b3)\
**Post date:** [July 25, 2019, 5:08pm UTC](https://forums.unrealengine.com/t/remove-physics-constraints-on-hit-event/452814/2 "2019-07-25T17:08:39Z")

</div>

Hey Bionic Ape,

If you’re using a component, try using this, but replace the MyComponent with your cars component name:  
MyComponent-\>SetSimulatePhysics(true);  
MyComponent-\>BodyInstance.bLockXLocation = true

Let me know if this helps, also feel free to send your code so I could take a look.

---

<div class="post-metadata">

**Author:** ![Bionic\_Ape](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bionic_ape/32/1090124_2.png) [@Bionic\_Ape](https://forums.unrealengine.com/u/Bionic_Ape)\
**Post date:** [July 25, 2019, 10:10pm UTC](https://forums.unrealengine.com/t/remove-physics-constraints-on-hit-event/452814/3 "2019-07-25T22:10:54Z")

</div>

Hi,

Thanks for your answer!

I might have not explained properly. The problem is “unlocking” the constraint before the simulation applies the force from the impact.

This is my code:

```
void UImpulseVehicleMovementComponent::OnHitCallback(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
{
	if (!bHadAnAccident && OtherActor && OtherActor->IsA(APawn::StaticClass()))
	{
		bHadAnAccident = true;

		SetPlaneConstraintNormal(FVector::ZeroVector);
		SetPlaneConstraintAxisSetting(EPlaneConstraintAxisSetting::Custom);
		FBodyInstance* pBodyInstance = UpdatedPrimitive->GetBodyInstance();
		pBodyInstance->CustomDOFPlaneNormal = FVector::ZeroVector;
		pBodyInstance->SetDOFLock(EDOFMode::CustomPlane);
		pBodyInstance->COMNudge = FVector::ZeroVector;
		pBodyInstance->UpdateMassProperties();
	}
}
```

---

<div class="post-metadata">

**Author:** ![Bionic\_Ape](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bionic_ape/32/1090124_2.png) [@Bionic\_Ape](https://forums.unrealengine.com/u/Bionic_Ape)\
**Post date:** [July 25, 2019, 10:13pm UTC](https://forums.unrealengine.com/t/remove-physics-constraints-on-hit-event/452814/4 "2019-07-25T22:13:09Z")

</div>

I have also tried this one:

```
	SetPlaneConstraintNormal(FVector::ZeroVector);
	SetPlaneConstraintAxisSetting(EPlaneConstraintAxisSetting::Custom);
	FBodyInstance* pBodyInstance = UpdatedPrimitive->GetBodyInstance();
	pBodyInstance->CustomDOFPlaneNormal = FVector::ZeroVector;
	pBodyInstance->SetDOFLock(EDOFMode::None);
	pBodyInstance->COMNudge = FVector::ZeroVector;
	pBodyInstance->UpdateMassProperties();
```
