5#include "PhysicalMaterials/PhysicalMaterial.h"
6#include "PhysicsEngine/PhysicsConstraintActor.h"
7#include "PhysicsEngine/PhysicsConstraintComponent.h"
10#include "DrawDebugHelpers.h"
14 Super(ObjectInitializer)
44 TArray<FBPGripPair> HoldingControllers;
47 IVRGripInterface::Execute_IsHeld(
GetParent(), HoldingControllers, bIsHeldOther);
59 int NumControllers = HoldingControllers.Num();
63 if (NumControllers > 1)
68 float GripDistanceOnPrimaryAxis = 0.f;
74 FVector localLoc = relTransform.GetTranslation();
133 if (GripInfo && GripInfoS)
135 FVector Primary = GripInfo->
RelativeTransform.InverseTransformPositionNoScale(FVector::ZeroVector);
136 FVector Secondary = GripInfoS->
RelativeTransform.InverseTransformPositionNoScale(FVector::ZeroVector);
149 FVector gripLoc = GripInfo->
RelativeTransform.InverseTransformPositionNoScale(FVector::ZeroVector);
154 FTransform ownerTrans =
GetOwner()->GetActorTransform();
173 LocDifference = FVector::ZeroVector;
183 FVector OriginalLoc = RelativeTrans.GetLocation();
184 FQuat OriginalRot = RelativeTrans.GetRotation();
193 FVector currentRelVec = orientationRot.RotateVector(ParentTransform.InverseTransformPosition(HandWorldTransform.GetLocation()));
194 FVector currentLoc = orientationRot.RotateVector(RelativeTrans.GetLocation());
195 currentLoc.X = currentRelVec.X;
196 RelativeTrans.SetLocation(orientationRot.UnrotateVector(currentLoc));
201 FRotator currentRelRot = (orientationRot * (ParentTransform.GetRotation().Inverse() * HandWorldTransform.GetRotation())).Rotator();
202 FRotator currentRot = (orientationRot * RelativeTrans.GetRotation()).Rotator();
203 currentRot.Roll = currentRelRot.Roll;
204 RelativeTrans.SetRotation(orientationRot.Inverse() * currentRot.Quaternion());
211 LocDifference = RelativeTrans.GetLocation() - OriginalLoc;
212 RotDifference = RelativeTrans.GetRotation().Rotator().Roll - OriginalRot.Rotator().Roll;
272 LocDifference = FVector::ZeroVector;
282 FVector OriginalLoc = RelativeTrans.GetLocation();
288 FVector currentRelVec = orientationRot.RotateVector(ParentTransform.InverseTransformPosition(HandWorldPosition));
291 FVector currentLoc = orientationRot.RotateVector(RelativeTrans.GetLocation());
292 currentLoc.X = currentRelVec.X;
294 RelativeTrans.SetLocation(orientationRot.UnrotateVector(currentLoc));
299 LocDifference = RelativeTrans.GetLocation() - OriginalLoc;
441 TArray<FBPGripPair> HoldingControllers;
479 HandleInfo->
LinConstraint.XDrive.bEnablePositionDrive =
true;
480 HandleInfo->
LinConstraint.XDrive.bEnableVelocityDrive =
true;
487 HandleInfo->
AngConstraint.SwingDrive.bEnablePositionDrive =
false;
488 HandleInfo->
AngConstraint.SwingDrive.bEnableVelocityDrive =
false;
489 HandleInfo->
AngConstraint.TwistDrive.bEnablePositionDrive =
false;
490 HandleInfo->
AngConstraint.TwistDrive.bEnableVelocityDrive =
false;
491 HandleInfo->
AngConstraint.AngularDriveMode = EAngularDriveMode::SLERP;
492 HandleInfo->
AngConstraint.SlerpDrive.bEnablePositionDrive =
true;
493 HandleInfo->
AngConstraint.SlerpDrive.bEnableVelocityDrive =
true;
522 FName CurrentCompName = NAME_None;
527 CurrentCompName = ChildComp->GetFName();
528 if (CurrentCompName == NAME_None)
533 bSearchRootComp =
false;
542 if (UPrimitiveComponent * PrimComp = Cast<UPrimitiveComponent>(ChildComp))
544 Found->TargetComponent = TWeakObjectPtr<UPrimitiveComponent>(PrimComp);
552 if (!bSearchRootComp && RemainingCount < 1)
577 if (!Hit.GetComponent())
593 TArray<FBPHitSurfaceProperties> AllowedPenetrationSurfaceTypes;
607 if (Hit.PhysMaterial.IsValid())
609 HitSurfaceProperties.
SurfaceType = Hit.PhysMaterial->SurfaceType;
612 if (AllowedPenetrationSurfaceTypes.Num())
615 if (!Hit.PhysMaterial.IsValid())
621 EPhysicalSurface PhysSurfaceType = Hit.PhysMaterial->SurfaceType;
622 int32 IndexOfSurface = AllowedPenetrationSurfaceTypes.IndexOfByPredicate([&PhysSurfaceType](
const FBPHitSurfaceProperties& Entry) {
return Entry.
SurfaceType == PhysSurfaceType; });
624 if (IndexOfSurface != INDEX_NONE)
626 HitSurfaceProperties = AllowedPenetrationSurfaceTypes[IndexOfSurface];
653 bool bHadFirstHit =
false;
656 float HitNormalImpulse = NormalImpulse.SizeSquared();
660 if (!LodgeData.TargetComponent.IsValid())
663 FBox LodgeLocalBox = LodgeData.TargetComponent->CalcLocalBounds().GetBox();
664 FVector LocalHit = LodgeData.TargetComponent->GetComponentTransform().InverseTransformPosition(Hit.ImpactPoint);
666 if (LodgeData.TargetComponent.IsValid() && LodgeLocalBox.IsInsideOrOn(LocalHit))
668 FVector ForwardVec = LodgeData.TargetComponent->GetForwardVector();
671 float DotValue = FMath::Abs(FVector::DotProduct(Hit.Normal, ForwardVec));
672 float Velocity = NormalImpulse.ProjectOnToNormal(ForwardVec).SizeSquared();
680 OnShouldLodgeInObject.Broadcast(LodgeData, OtherActor, Hit.GetComponent(), Hit.GetComponent()->GetCollisionObjectType(), HitSurfaceProperties, NormalImpulse, Hit);
686 float HitImpulse = LodgeData.bIgnoreForwardVectorForHitImpulse ? HitNormalImpulse : Velocity;
688 if (!bHadFirstHit && LodgeData.ZoneType >
EVRMeleeZoneType::VRPMELLE_ZONETYPE_Stab && DotValue >= (1.0f - LodgeData.AcceptableForwardProductRangeForHits) && HitImpulse >= FMath::Square(LodgeData.MinimumHitVelocity))
691 FirstHitComp = LodgeData;
698 OnMeleeHit.Broadcast(FirstHitComp, OtherActor, Hit.GetComponent(), Hit.GetComponent()->GetCollisionObjectType(), HitSurfaceProperties, NormalImpulse, Hit);
718 KinPose.SetRotation(KinPose.GetRotation() * (HandleInfo->
RootBoneRotation.GetRotation().Inverse() * DeltaQuat));
764 if (!GrippingController || !HandleInfo)
773 if (FBodyInstance * rBodyInstance = PrimComp->GetBodyInstance())
775 FPhysicsCommand::ExecuteWrite(rBodyInstance->ActorHandle, [&](
const FPhysicsActorHandle&
Actor)
777 FTransform localCom = FPhysicsInterface::GetComTransformLocal_AssumesLocked(Actor);
778 localCom.SetLocation((HandleInfo->RootBoneRotation * ObjectRelativeGripCenter).GetLocation());
779 FPhysicsInterface::SetComLocalPose_AssumesLocked(Actor, localCom);
819 float DeltaTime, FTransform & WorldTransform,
820 const FTransform &ParentTransform,
823 UPrimitiveComponent * root,
824 bool bRootHasInterface,
825 bool bActorHasInterface,
829 if (!GrippingController)
876 if (bRootHasInterface)
877 SecondaryType = IVRGripInterface::Execute_SecondaryGripType(root);
878 else if (bActorHasInterface)
879 SecondaryType = IVRGripInterface::Execute_SecondaryGripType(actor);
885 FVector BasePoint = ParentTransform.GetLocation();
886 const FTransform PivotToWorld = FTransform(FQuat::Identity, BasePoint);
887 const FTransform WorldToPivot = FTransform(FQuat::Identity, -BasePoint);
889 FVector frontLocOrig;
916 FVector Scaler = FVector(1.0f);
919 GetAnyScaling(Scaler, Grip, frontLoc, frontLocOrig, SecondaryType, SecondaryTransform);
934 FQuat rotVal = FQuat::FindBetweenVectors(frontLocOrig, frontLoc);
937 WorldTransform = WorldTransform * WorldToPivot * FTransform(rotVal, FVector::ZeroVector, Scaler) * PivotToWorld;
942 WorldTransform = WorldTransform * WorldToPivot * FTransform(FQuat::Identity, FVector::ZeroVector, Scaler) * PivotToWorld;
954 FVector origLocation = InverseTrans.GetLocation();
959 FQuat DeltaQuat = FQuat::FindBetweenVectors(orientedvector, newLocation);
961 WorldTransform.SetRotation(DeltaQuat * WorldTransform.GetRotation());
@ VRPMELEECOM_BetweenHands
@ VRPMELEECOM_PrimaryHand
ESecondaryGripType
UENUM(Blueprintable)
@ SG_FreeWithScaling_Retain
@ SG_SlotOnlyWithScaling_Retain
@ COM_GripAtControllerLoc
virtual void GetAnyScaling(FVector &Scaler, FBPActorGripInformation &Grip, FVector &frontLoc, FVector &frontLocOrig, ESecondaryGripType SecondaryType, FTransform &SecondaryTransform)
virtual void ApplySmoothingAndLerp(FBPActorGripInformation &Grip, FVector &frontLoc, FVector &frontLocOrig, float DeltaTime)
virtual void CalculateSecondaryLocation(FVector &frontLoc, const FVector &BasePoint, FBPActorGripInformation &Grip, UGripMotionControllerComponent *GrippingController)
FTransform OrientationComponentRelativeFacing
EVRMeleePrimaryHandType PrimaryHandSelectionType
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Settings")
TArray< FBPLodgeComponentInfo > PenetrationNotifierComponents
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Settings")
UGS_Melee(const FObjectInitializer &ObjectInitializer)
virtual bool Wants_DenyTeleport_Implementation(UGripMotionControllerComponent *Controller) override
bool bOnlyPenetrateWithTwoHands
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Melee|Lodging")
bool bUsePrimaryHandSettingsWithOneHand
UPROPERTY(BlueprintReadOnly, Category = "Weapon Settings")
virtual void OnGrip_Implementation(UGripMotionControllerComponent *GrippingController, const FBPActorGripInformation &GripInformation) override
bool bHasValidPrimaryHand
virtual void OnLodgeHitCallback(AActor *SelfActor, AActor *OtherActor, FVector NormalImpulse, const FHitResult &Hit)
UFUNCTION()
void SetPrimaryAndSecondaryHands(FBPGripPair &PrimaryGrip, FBPGripPair &SecondaryGrip)
UFUNCTION(BlueprintCallable, Category = "Weapon Settings")
void SetComBetweenHands(UGripMotionControllerComponent *GrippingController, FBPActorPhysicsHandleInformation *HandleInfo)
FVROnMeleeOnHit OnMeleeHit
UPROPERTY(BlueprintAssignable, Category = "Melee|Hit")
FVROnMeleeInvalidHitSignature OnMeleeInvalidHit
UPROPERTY(BlueprintAssignable, Category = "Melee|Hit")
EVRMeleeComType COMType
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Settings")
FBPGripPair SecondaryHand
UPROPERTY(BlueprintReadOnly, Category = "Weapon Settings")
void UpdateHandPosition(FBPGripPair HandPair, FVector HandWorldPosition, FVector &LocDifference)
UFUNCTION(BlueprintCallable, Category = "Weapon Settings")
FBPAdvancedPhysicsHandleSettings SecondaryHandPhysicsSettings
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Settings")
virtual void HandlePrePhysicsHandle(UGripMotionControllerComponent *GrippingController, const FBPActorGripInformation &GripInfo, FBPActorPhysicsHandleInformation *HandleInfo, FTransform &KinPose) override
virtual void OnSecondaryGrip_Implementation(UGripMotionControllerComponent *Controller, USceneComponent *SecondaryGripComponent, const FBPActorGripInformation &GripInformation) override
FTransform ObjectRelativeGripCenter
virtual bool GetWorldTransform_Implementation(UGripMotionControllerComponent *GrippingController, float DeltaTime, FTransform &WorldTransform, const FTransform &ParentTransform, FBPActorGripInformation &Grip, AActor *actor, UPrimitiveComponent *root, bool bRootHasInterface, bool bActorHasInterface, bool bIsForTeleport) override
FBPGripPair PrimaryHand
UPROPERTY(BlueprintReadOnly, Category = "Weapon Settings")
virtual void OnEndPlay_Implementation(const EEndPlayReason::Type EndPlayReason) override
FName WeaponRootOrientationComponent
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Settings")
virtual void OnGripRelease_Implementation(UGripMotionControllerComponent *ReleasingController, const FBPActorGripInformation &GripInformation, bool bWasSocketed=false) override
void UpdateHandPositionAndRotation(FBPGripPair HandPair, FTransform HandWorldTransform, FVector &LocDifference, float &RotDifference, bool bUpdateLocation=true, bool bUpdateRotation=true)
UFUNCTION(BlueprintCallable, Category = "Weapon Settings")
FBPAdvancedPhysicsHandleSettings PrimaryHandPhysicsSettings
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Settings")
FVROnMeleeShouldLodgeSignature OnShouldLodgeInObject
UPROPERTY(BlueprintAssignable, Category = "Melee|Lodging")
void UpdateDualHandInfo()
bool bAlwaysTickPenetration
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Melee|Lodging")
virtual void HandlePostPhysicsHandle(UGripMotionControllerComponent *GrippingController, FBPActorPhysicsHandleInformation *HandleInfo) override
virtual void OnBeginPlay_Implementation(UObject *CallingOwner) override
bool bAutoSetPrimaryAndSecondaryHands
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Settings")
TArray< FBPHitSurfaceProperties > OverrideMeleeSurfaceSettings
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Melee|Lodging")
UCLASS(Blueprintable, meta = (BlueprintSpawnableComponent), ClassGroup = MotionController)
bool UpdatePhysicsHandle(uint8 GripID, bool bFullyRecreate=true)
void NotifyGripTransformChanged(const FBPActorGripInformation &GripInfo)
FORCEINLINE FVector GetPivotLocation()
FBPActorPhysicsHandleInformation * GetPhysicsGrip(const FBPActorGripInformation &GripInfo)
FBPActorGripInformation * GetGripPtrByID(uint8 IDToLookForGrip)
static void GetMeleeSurfaceGlobalSettings(TArray< FBPHitSurfaceProperties > &OutMeleeSurfaceSettings)
UFUNCTION(BlueprintCallable, Category = "MeleeSettings")
bool bInjectPostPhysicsHandle
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "GSSettings")
FTransform GetParentTransform(bool bGetWorldTransform=true, FName BoneName=NAME_None)
UFUNCTION(BlueprintPure, Category = "VRGripScript")
bool bInjectPrePhysicsHandle
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "GSSettings")
bool bDenyLateUpdates
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "GSSettings")
EGSTransformOverrideType WorldTransformOverrideType
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "GSSettings")
bool bIsActive
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "GSSettings")
AActor * GetOwner()
UFUNCTION(BlueprintPure, Category = "VRGripScript")
bool bCanEverTick
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "TickSettings")
USceneComponent * GetParentSceneComp()
UFUNCTION(BlueprintCallable, Category = "VRGripScript")
UObject * GetParent()
UFUNCTION(BlueprintPure, Category = "VRGripScript")
EPhysicsGripCOMType PhysicsGripLocationSettings
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PhysicsSettings", meta = (editcondition = "bU...
bool bUsePhysicsSettings
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PhysicsSettings")
float AngularDamping
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PhysicsSettings", meta = (editcondition = "bU...
bool bUseCustomAngularValues
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PhysicsSettings", meta = (editcondition = "bU...
float AngularStiffness
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PhysicsSettings", meta = (editcondition = "bU...
USTRUCT(BlueprintType, Category = "VRExpansionLibrary")
FBPAdvGripPhysicsSettings PhysicsSettings
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AdvancedGripSettings")
bool FillTo(FBPActorPhysicsHandleInformation *HandleInfo) const
USTRUCT(BlueprintType, Category = "VRExpansionLibrary")
UGripMotionControllerComponent * HoldingController
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GripPair")
uint8 GripID
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GripPair")
USTRUCT(BlueprintType, Category = "Lodging")
bool bSurfaceAllowsPenetration
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Surface Property")
TEnumAsByte< EPhysicalSurface > SurfaceType
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Surface Property")
float StabVelocityScaler
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Surface Property")
USTRUCT(BlueprintType, Category = "Lodging")
USceneComponent * SecondaryAttachment
UPROPERTY(BlueprintReadOnly, Category = "SecondaryGripInfo")
EGripLerpState GripLerpState
float LerpToRate
UPROPERTY()
float SecondaryGripDistance
UPROPERTY(BlueprintReadOnly, NotReplicated, Category = "SecondaryGripInfo")
FVector LastRelativeLocation
bool bHasSecondaryAttachment
UPROPERTY(BlueprintReadOnly, Category = "SecondaryGripInfo")
FTransform_NetQuantize SecondaryRelativeTransform
UPROPERTY(BlueprintReadOnly, Category = "SecondaryGripInfo")