Hi, please help me to understand the rotation of physical objects related to Physical Constraint.
There are two kinds of objects:
- A standard door (microwave door), as you can see in the video, it works perfectly and rotates via AddRadialImpulseToBody.
- A door that opens from top to bottom, rotating it via AddRadialImpulseToBody function doesn’t work, so considering that the direction of movement is different, I try to do it via AddAngularImpulseInRadians function, but it works very strange.
I tried to video all the details and differences in operation, I will be glad for any help.
All the best!
Here is my code
HDoor (works nice)
void UVRGrabHDoorComponent::TickComponent(float DeltaTime, ELevelTick TickType,
FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
if (IsGrabbed())
{
const FRotator LookAndRotation = UKismetMathLibrary::FindLookAtRotation(
GetComponentLocation(), MotionControllerComponent->GetComponentLocation());
const float ImpulseStrength = UKismetMathLibrary::NormalizeAxis(
LookAndRotation.Vector().Dot(GetRightVector()));
const UStaticMeshComponent* MeshComponent = GetAttachParentActor()->GetComponentByClass<UStaticMeshComponent>();
MeshComponent->GetBodyInstance()->AddRadialImpulseToBody(GetComponentLocation(), 20.0f,
ImpulseStrength * ImpulseForce,
RIF_Constant, false);
}
}
VDoor (works wrong)
void UVRGrabVDoorComponent::TickComponent(float DeltaTime, ELevelTick TickType,
FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
if (IsGrabbed())
{
const FRotator LookAndRotation = UKismetMathLibrary::FindLookAtRotation(
GetComponentLocation(), MotionControllerComponent->GetComponentLocation());
const float ImpulseStrength = UKismetMathLibrary::NormalizeAxis(
LookAndRotation.Vector().Dot(GetRightVector()));
const UStaticMeshComponent* MeshComponent = GetAttachParentActor()->GetComponentByClass<UStaticMeshComponent>();
MeshComponent->GetBodyInstance()->AddAngularImpulseInRadians(FVector(0, -ImpulseStrength * 2000.0f, 0),
false);
}
}