7#include "Kismet/GameplayStatics.h"
8#include "Kismet/KismetMathLibrary.h"
115 FTransform RelativeToHandWorldTransform = GrabbedHand->
MotionController->GetComponentTransform();
117 RelativeToHandWorldTransform.SetTranslation(RelativeToHandWorldTransform.TransformPosition(InHandOffsetTransform.GetTranslation()));
118 RelativeToHandWorldTransform.SetRotation(RelativeToHandWorldTransform.GetRotation() * InHandOffsetTransform.GetRotation());
119 RelativeToHandWorldTransform.SetScale3D(InHandOffsetTransform.GetScale3D());
121 return RelativeToHandWorldTransform;
124 return GetTransform();
129 Super::ObjectActivated_Implementation();
139 Super::ObjectDeactivated_Implementation();
163 OnGripped.Broadcast(GrippingController, GripInformation);
175 OnGripped.Broadcast(GrippingController, GripInformation);
178 OnGripped.Broadcast(GrippingController, GripInformation);
202 OnDropped.Broadcast(ReleasingController, GripInformation, bWasSocketed);
286 if (OverridePrefix.IsNone())
287 bSecondarySlot ? OverridePrefix =
"VRGripS" : OverridePrefix =
"VRGripP";
289 UVRExpansionFunctionLibrary::GetGripSlotInRangeByTypeName(OverridePrefix,
this, WorldLocation, bSecondarySlot ?
VRGripInterfaceSettings.SecondarySlotRange :
VRGripInterfaceSettings.PrimarySlotRange, bHadSlotInRange, SlotWorldTransform, SlotName, CallingController);
333 DisableComponentsSimulatePhysics();
345 OnGripped.Broadcast(GrippingController, GripInformation);
350 FDetachmentTransformRules DetachmentTransformRules(EDetachmentRule::KeepWorld,
false);
351 DetachFromActor(DetachmentTransformRules);
352 if (IVRGripInterface::Execute_SimulateOnDrop(
this))
356 if (UPrimitiveComponent* PrimComp = Cast<UPrimitiveComponent>(Component))
358 PrimComp->SetSimulatePhysics(
true);
366 Super::GrabWithTwoHands_Implementation(GrabbingController);
369 APixoVRCharacter* PlayerRef = Cast<APixoVRCharacter>(UGameplayStatics::GetPlayerPawn(GetWorld(), 0));
374 GrabbingHand.Get()->GetOverlappingActor(OverlappingInfo);
385 DetachFromActor(FDetachmentTransformRules::KeepWorldTransform);
389 Cast<APixoVRCharacter>(UGameplayStatics::GetPlayerPawn(GetWorld(), 0))->HoldToolRight =
true;
390 Cast<APixoVRCharacter>(UGameplayStatics::GetPlayerPawn(GetWorld(), 0))->HoldToolLeft =
true;
393 for (
const auto FakeHand : IPixoVRStoryObject::Execute_GetTwoHandProperties(
this).FakeHands)
395 FakeHand->SetVisibility(
true);
407 Super::ReleaseTwoHands_Implementation(ReleasingController);
415 for (
const auto FakeHand : IPixoVRStoryObject::Execute_GetTwoHandProperties(
this).FakeHands)
417 FakeHand->SetVisibility(
false);
419 Cast<APixoVRCharacter>(UGameplayStatics::GetPlayerPawn(GetWorld(), 0))->ResetHand(
true);
420 Cast<APixoVRCharacter>(UGameplayStatics::GetPlayerPawn(GetWorld(), 0))->ResetHand(
false);
421 IPixoVRStoryObject::Execute_ResetTwoHandsHoldingFunctionality(
this);
434 for (
const auto FakeHand : IPixoVRStoryObject::Execute_GetTwoHandProperties(
this).FakeHands)
436 FakeHand->SetVisibility(
false);
440 if (ReleasingController->MotionSource.IsEqual(
"Right"))
442 Cast<APixoVRCharacter>(UGameplayStatics::GetPlayerPawn(GetWorld(), 0))->ResetHand(
true);
448 Cast<APixoVRCharacter>(UGameplayStatics::GetPlayerPawn(GetWorld(), 0))->ResetHand(
false);
456 ActiveHandAfterRelease->
MotionController->GripObjectByInterface(
this, IPixoVRStoryObject::Execute_GetObjectGrabTransform(
this, ActiveHandAfterRelease));
460 this->AttachToComponent(ActiveHandAfterRelease->
MotionController, FAttachmentTransformRules::SnapToTargetNotIncludingScale);
473 Super::ResetTwoHandsHoldingFunctionality_Implementation();
482 for (
const auto FakeHand : IPixoVRStoryObject::Execute_GetTwoHandProperties(
this).FakeHands)
484 FakeHand->SetVisibility(
false);
513 APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0);
515 if (PixoVRPlayerController)
517 EControllerHand Hand;
518 GripMotionControllerComponent->GetHandType(Hand);
529 UGameplayStatics::PlaySoundAtLocation(
this,
GripSoundCue, GetActorLocation());
537 UGameplayStatics::PlaySoundAtLocation(
this,
ReleaseSoundCue, GetActorLocation());
546 const FRotator HandDirectionRotator = UKismetMathLibrary::ComposeRotators(UKismetMathLibrary::FindLookAtRotation(
PixoVRHandRight->GrabSphere->GetComponentLocation(),
PixoVRHandLeft->GrabSphere->GetComponentLocation()), FRotator(0.0, -90.0, 0.0));
547 if (
CrossDetected && IPixoVRStoryObject::Execute_GetTwoHandProperties(
this).EnableFlip)
549 if (HandDirectionRotator.Pitch <= 0.0)
559 else if (
CrossDetected && !IPixoVRStoryObject::Execute_GetTwoHandProperties(
this).EnableFlip)
565 if (HandDirectionRotator.Pitch <= 0.0)
589 ObjectRelatedHandLocation.Z -= IPixoVRStoryObject::Execute_GetTwoHandProperties(
this).ZAxisOffsetInHands;
590 SetActorLocation(ObjectRelatedHandLocation);
593 if (IPixoVRStoryObject::Execute_GetTwoHandProperties(
this).EnableDebug)
595 GEngine->AddOnScreenDebugMessage(-1, 0.01, FColor::Red, FString::Printf(TEXT(
"Right hand distance to object - %f"), (
PixoVRHandRight->GrabSphere->GetComponentLocation() - GetActorLocation()).Size()));
596 GEngine->AddOnScreenDebugMessage(-1, 0.01, FColor::Blue, FString::Printf(TEXT(
"Left hand distance to object - %f"), (
PixoVRHandLeft->GrabSphere->GetComponentLocation() - GetActorLocation()).Size()));
597 GEngine->AddOnScreenDebugMessage(-1, 0.01, FColor::Black, FString::Printf(TEXT(
"Detach distance - %f"), (IPixoVRStoryObject::Execute_GetTwoHandProperties(
this).ControllerDetachDistance)));
598 GEngine->AddOnScreenDebugMessage(-1, 0.01, FColor::Black, FString::Printf(TEXT(
"Cross detected - %s"),
CrossDetected ? TEXT(
"true") : TEXT(
"false")));
599 DrawDebugSphere(GetWorld(), (
PixoVRHandRight->GrabSphere->GetComponentLocation() - (
PixoVRHandRight->GrabSphere->GetComponentLocation()-
PixoVRHandLeft->GrabSphere->GetComponentLocation())/2), 3.0, 10, FColor::Yellow,
false, 0.1);
601 if ((
PixoVRHandRight->GrabSphere->GetComponentLocation() - GetActorLocation()).Size() > (IPixoVRStoryObject::Execute_GetTwoHandProperties(
this).ControllerDetachDistance))
602 IPixoVRStoryObject::Execute_ReleaseTwoHands(
this,
PixoVRHandRight->MotionController);
603 if ((
PixoVRHandLeft->GrabSphere->GetComponentLocation() - GetActorLocation()).Size() > (IPixoVRStoryObject::Execute_GetTwoHandProperties(
this).ControllerDetachDistance))
604 IPixoVRStoryObject::Execute_ReleaseTwoHands(
this,
PixoVRHandLeft->MotionController);
611 const APixoVRCharacter* PlayerRef =Cast<APixoVRCharacter>(UGameplayStatics::GetPlayerPawn(GetWorld(),0));
612 FVector CameraRightHandV = PlayerRef->
VRHandRight->
GrabSphere->GetComponentLocation() - PlayerRef->VRReplicatedCamera->GetComponentLocation();
613 FVector CameraLeftHandV = PlayerRef->
VRHandLeft->
GrabSphere->GetComponentLocation() - PlayerRef->VRReplicatedCamera->GetComponentLocation();
614 if (!CameraRightHandV.Normalize())
615 GEngine->AddOnScreenDebugMessage(-1, 10.0, FColor::Orange, FString::Printf(TEXT(
"Bad normalization CameraRightHandV")));
616 if (!CameraLeftHandV.Normalize())
617 GEngine->AddOnScreenDebugMessage(-1, 10.0, FColor::Orange, FString::Printf(TEXT(
"Bad normalization CameraLeftHandV")));
619 FVector RightLeftHandV = CameraRightHandV + CameraLeftHandV;
620 if (!RightLeftHandV.Normalize())
621 GEngine->AddOnScreenDebugMessage(-1, 10.0, FColor::Orange, FString::Printf(TEXT(
"Bad normalization CameraLeftHandV")));
623 const FVector Cross = FVector::CrossProduct(CameraRightHandV, RightLeftHandV);
625 if (IPixoVRStoryObject::Execute_GetTwoHandProperties(
this).EnableDebug)
627 GEngine->AddOnScreenDebugMessage(-1, 0.01, FColor::Orange, FString::Printf(TEXT(
"RightLeftHandV x - %f, y - %f, z - %f"), RightLeftHandV.X, RightLeftHandV.Y, RightLeftHandV.Z));
628 GEngine->AddOnScreenDebugMessage(-1, 0.01, FColor::Orange, FString::Printf(TEXT(
"VRHandRight x - %f, y - %f, z - %f"), PlayerRef->
VRHandRight->GetActorLocation().X, PlayerRef->
VRHandRight->GetActorLocation().Y, PlayerRef->
VRHandRight->GetActorLocation().Z));
629 GEngine->AddOnScreenDebugMessage(-1, 0.01, FColor::Orange, FString::Printf(TEXT(
"CameraRightHandV x - %f, y - %f, z - %f"), CameraRightHandV.X, CameraRightHandV.Y, CameraRightHandV.Z));
630 GEngine->AddOnScreenDebugMessage(-1, 0.01, FColor::Orange, FString::Printf(TEXT(
"Z cross - %f"), Cross.Z));
641 MoveBackPitchDelta = FMath::Abs(FMath::Abs(CurrentPitch) - FMath::Abs(RightLeftHandVPitch));
EHandGripLogic
Enum representing the different hand grip logic options.
@ AttachToHandWithCustomTransform
@ NativeVRGripInterfaceSettings
@ CustomTransformAttachWithPhysics
virtual void ReleaseTwoHands_Implementation(UMotionControllerComponent *ReleasingController) override
virtual void SendWrongGrabbingNotification_Implementation() override
Implementation of the SendErrorGrabbingNotification function from the IPixoVRStoryObject interface....
bool EnableOnePressDetach
TWeakObjectPtr< UMotionControllerComponent > TwoHandMainGrabController
virtual void OnGripRelease_Implementation(UGripMotionControllerComponent *ReleasingController, const FBPActorGripInformation &GripInformation, bool bWasSocketed) override
Implementation of the OnGripRelease function from the IVRGripInterface interface. Event triggered on ...
void PlayGripSound() const
TWeakObjectPtr< APixoVRHand > PixoVRHandLeft
void PlayHapticFeedbackEffect(UGripMotionControllerComponent *GripMotionControllerComponent) const
Plays haptic feedback on specific controller.
virtual EGripMovementReplicationSettings GripMovementReplicationType_Implementation() override
Implementation of the GripMovementReplicationType function from the IVRGripInterface interface....
FOnDroppedActorDeleted OnDroppedActorDeleted
UPROPERTY(BlueprintReadWrite, BlueprintCallable, BlueprintAssignable)
virtual void GetGripStiffnessAndDamping_Implementation(float &GripStiffnessOut, float &GripDampingOut) override
Implementation of the GetGripStiffnessAndDamping function from the IVRGripInterface interface....
float HapticStrength
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Feedback Effect", meta=(EditCondition = "bFee...
void UpdateHandGripLogic(EHandGripLogic NewHandGripLogic)
Updates the hand grip logic.
FVROnGripSignature OnSecondaryGripAdded
UPROPERTY(BlueprintAssignable, Category = "Grip Events")
virtual void ClosestGripSlotInRange_Implementation(FVector WorldLocation, bool bSecondarySlot, bool &bHadSlotInRange, FTransform &SlotWorldTransform, FName &SlotName, UGripMotionControllerComponent *CallingController=nullptr, FName OverridePrefix=NAME_None) override
Implementation of the ClosestGripSlotInRange function from the IVRGripInterface interface....
bool StoryActivationAffectsDenyGripping
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "GrippableObject")
void AttachToHandObject(UGripMotionControllerComponent *GrippingController, const FBPActorGripInformation &GripInformation)
Attaches the object to a hand.
FTransform ResetTransform
UPROPERTY(BlueprintReadOnly, Category = "GrippableObject")
virtual ESecondaryGripType SecondaryGripType_Implementation() override
Implementation of the SecondaryGripType function from the IVRGripInterface interface....
bool bSaveResetTransformOnGrip
Flag for preventing this objet from saving ResetTransform.
virtual void OnSecondaryGripRelease_Implementation(UGripMotionControllerComponent *GripOwningController, USceneComponent *ReleasingSecondaryGripComponent, const FBPActorGripInformation &GripInformation) override
Implementation of the OnSecondaryGripRelease function from the IVRGripInterface interface....
float TimeSinceResetTimerStarted
Time that accumulates after PositionResetTimer has started.
void StopPositionResetTimer()
Stopping the current position reset check timer.
void StartPositionResetTimer()
Stopping new position reset check timer.
EHandGripLogic HandGripLogic
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "GrippableObject")
void DetachObjectFromHand()
Detaches the object from the hand.
virtual void GrabWithTwoHands_Implementation(UMotionControllerComponent *GrabbingController) override
Two hand grabbing logic implementation.
void HandCrossDetection(float CurrentPitch, float RightLeftHandVPitch)
void CheckPositionResetConditions()
Checking if this object's position can be reset.
virtual FTransform GetObjectGrabTransform_Implementation(APixoVRHand *GrabbedHand) override
Implementation of the GetObjectGrabTransform function from the IPixoVRStoryObject interface....
FTransform ObjectTransformInRightHand
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GrippableObject")
FVROnGripSignature OnSecondaryGripRemoved
UPROPERTY(BlueprintAssignable, Category = "Grip Events")
float HapticDuration
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Feedback Effect", meta=(EditCondition = "bFee...
bool bGripSoundsEnabled
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Feedback Effect")
USoundCue * ReleaseSoundCue
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Feedback Effect", meta = (EditCondition = "bR...
FVROnDropSignature OnDropped
UPROPERTY(BlueprintAssignable, Category = "Grip Events")
virtual void SetHeld_Implementation(UGripMotionControllerComponent *HoldingController, uint8 GripID, bool bIsHeld) override
Implementation of the SetHeld function from the IVRGripInterface interface. Sets is held,...
virtual EGripInterfaceTeleportBehavior TeleportBehavior_Implementation() override
Implementation of the TeleportBehavior function from the IVRGripInterface interface....
virtual float GripBreakDistance_Implementation() override
Implementation of the GripBreakDistance function from the IVRGripInterface interface....
virtual void IsHeld_Implementation(TArray< FBPGripPair > &HoldingControllers, bool &bIsHeld) override
Implementation of the IsHeld function from the IVRGripInterface interface. Returns if the object is h...
virtual void EnableOnePressDetach_Implementation(bool Enable) override
UStaticMeshComponent * StaticMeshComponent
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Components")
bool bDestroyActorAfterFailedDrop
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "GrippableObject")
virtual bool IsGrabbingWrongActorActive_Implementation() override
Implementation of the IsGrabbingWrongActorActive function from the IPixoVRStoryObject interface....
FVROnGripSignature OnGripped
UPROPERTY(BlueprintAssignable, Category = "Grip Events")
virtual EGripLateUpdateSettings GripLateUpdateSetting_Implementation() override
Implementation of the GripLateUpdateSetting function from the IVRGripInterface interface....
float PositionResetCheckRate
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GrippableObject")
void OnGrippedEvent(UGripMotionControllerComponent *GrippingController, const FBPActorGripInformation &GripInformation)
Event triggered when the object is gripped.
bool bActivateLocationResetAfterDrop
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "GrippableObject")
virtual void OnSecondaryGrip_Implementation(UGripMotionControllerComponent *GripOwningController, USceneComponent *SecondaryGripComponent, const FBPActorGripInformation &GripInformation) override
Implementation of the OnSecondaryGrip function from the IVRGripInterface interface....
TWeakObjectPtr< APixoVRHand > PixoVRHandRight
virtual bool DenyGripping_Implementation(UGripMotionControllerComponent *GripInitiator=nullptr) override
Implementation of the DenyGripping function from the IVRGripInterface interface. Set up as deny inste...
USoundCue * GripSoundCue
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Feedback Effect", meta = (EditCondition = "bG...
virtual bool IsObjectHeldWithTwoHands_Implementation() override
APixoVRHand * CurrentHoldingHand
UPROPERTY(VisibleInstanceOnly, BlueprintReadWrite, Category = "GrippableObject")
ABaseGrippableStoryActor()
virtual void UpdateObjectHighlight_Implementation(bool Activate) override
Implementation of the UpdateObjectHighlight function from the IPixoVRStoryObject interface.
void ResetPosition()
Resetting object to the position it has ben grabbed off.
bool bCanResetPosition
UPROPERTY(BlueprintReadWrite, Category = "GrippableObject")
float PositionResetMaximumDelay
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GrippableObject")
FTimerHandle PositionResetTimer
Internal timer for checking object's conditions for position reset.
virtual bool SimulateOnDrop_Implementation() override
Implementation of the SimulateOnDrop function from the IVRGripInterface interface....
virtual void ObjectActivated_Implementation() override
Implementation of the ObjectActivated function from the IPixoVRStoryObject interface.
FBPInterfaceProperties VRGripInterfaceSettings
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
FOnActorStopped OnActorStoppedDelegate
UPROPERTY(BlueprintReadWrite, BlueprintCallable, BlueprintAssignable)
FOnActorStopped OnActorPositionResetDelegate
UPROPERTY(BlueprintReadWrite, BlueprintCallable, BlueprintAssignable)
FTransform ObjectTransformInLeftHand
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GrippableObject")
virtual void OnGrip_Implementation(UGripMotionControllerComponent *GrippingController, const FBPActorGripInformation &GripInformation) override
Implementation of the OnGrip function from the IVRGripInterface interface. Event triggered on the int...
bool bFeedbackEnabled
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Feedback Effect")
virtual FBPAdvGripSettings AdvancedGripSettings_Implementation() override
Implementation of the AdvancedGripSettings function from the IVRGripInterface interface....
bool bReleaseSoundsEnabled
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Feedback Effect")
void OnReleasedEvent(UGripMotionControllerComponent *ReleasingController, const FBPActorGripInformation &GripInformation, bool bWasSocketed)
Event triggered when the object is released from the grip.
virtual void BeginPlay() override
virtual EGripCollisionType GetPrimaryGripType_Implementation(bool bIsSlot) override
Implementation of the GetPrimaryGripType function from the IVRGripInterface interface....
virtual void ResetTwoHandsHoldingFunctionality_Implementation() override
void PlayReleaseSound() const
bool ObjectHeldWithTwoHands
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Two Hands Grip")
virtual bool AllowsMultipleGrips_Implementation() override
Implementation of the AllowsMultipleGrips function from the IVRGripInterface interface....
FTimerHandle TwoHandTimer
virtual void ObjectDeactivated_Implementation() override
Implementation of the ObjectDeactivated function from the IPixoVRStoryObject interface.
UStoryComponent * Story
UPROPERTY(BlueprintReadWrite, EditAnywhere)
UHighlightComponent * HighlightComponent
UPROPERTY(EditAnywhere, BlueprintReadWrite)
Pixo VR Character This class represents the main character in the Pixo VR game. It extends the AVRCha...
bool bActivateRightLaser
UPROPERTY(BlueprintReadOnly, Replicated)
bool bActivateLeftLaser
UPROPERTY(BlueprintReadOnly, Replicated)
APixoVRHand * VRHandLeft
UPROPERTY(BlueprintReadOnly, Category = "Hands")
APixoVRHand * VRHandRight
UPROPERTY(BlueprintReadOnly, Category = "Hands")
void ActivateLaserBeam(EControllerHand Hand, bool InActivate)
Activate/Deactivate the Laser-beam.
bool bLaserBeamActive
UPROPERTY(BlueprintReadWrite, Category = "PixoVR")
APixoVRHand is an actor class that represents a hand in the VR environment.
UGripMotionControllerComponent * MotionController
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Components")
USphereComponent * GrabSphere
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Components")
EControllerHand HandMotionSource
UPROPERTY(BlueprintReadWrite, Category = "Init", meta = (ExposeOnSpawn = "true"))
A custom player controller class for PixoVR.
void PlayHapticFeedback(bool RightHand, float Duration, float Strength)
UFUNCTION(BlueprintCallable, Category = "Haptic")
FOnWrongInteractableActorGrabbed OnWrongInteractableActorGrabbed
UPROPERTY(BlueprintReadWrite, BlueprintCallable, BlueprintAssignable)
bool bWrongInteractableActorGrabEnabled
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "GameManager|WrongActionFeedback")
FTimerHandle PulseHighlightTimerHandle
UPROPERTY(BlueprintReadWrite)
void UpdateHighlightValue(EHighlightColor HighlightColor)
Updates the highlight color of the object.
UGameManager * GameManager
UPROPERTY(BlueprintReadOnly, Category = "Story|Setup")
FOverlappingInfo is a structure that holds information about overlapping actors and components.