Remove Physics Constraints On Hit event

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?

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.

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();
	}
}

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();