Hi,
I recently started at working with Unreal engine and cant find my answer yet. Based on the Blueprint in the physics map of Content Examples, I have tried to implement functions including grabbing and moving a physical object in C++.
My problem is that the grabbed object does not move at all. Below is my Tick code and I checked LatestHandleLocation is updated whenever I moved the player while grabbing the object but grabbed object is stuck in the position where mouse button pressed. Please let me know how I can move the object grabbed by player. I want to keep holding position need to be somewhere in front of player.
The attached picture is the blueprint what I tried to convert into C++. This is third person shooter game style.
void ATutorialCodeCharacter::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
GetCharacterMovement()->MaxWalkSpeed = SpeedFactor * PowerLevel + BaseSpeed;
FVector curPos = GetActorLocation();
curPos.Y = InitialYPos;
SetActorLocation(curPos);
// Update the position of the Physics Handle to be always in front of the Player
if (PhysicsHandleActive == true)
{
#if 0
TArray<UBillboardComponent*> Comps;
GetComponents(Comps);
if(Comps.Num() > 0)
{
UBillboardComponent* FoundComp = Comps[0];
//do stuff with FoundComp
LatestHandleLocation = FoundComp->GetComponentLocation();
}
#else
FRotator curRot = GetActorRotation();
// get forward vector
FVector Direction = FRotationMatrix(curRot).GetUnitAxis(EAxis::X);
FVector newPos = HandleDistance * Direction;
newPos = newPos + curPos;
newPos.Z += 50;
LatestHandleLocation = newPos;
#endif
if (PhysicsHandle)
PhysicsHandle->SetTargetLocation(LatestHandleLocation);
}
}