上一节是绑定了抓取物品:
现在要移动物品:
if(PhysicsHandle && PhysicsHandle->GrabbedComponent)
{
PhysicsHandle->SetTargetLocation(GetLineEnd());
}
PhysicsHandle ->ReleaseComponent();
上一节是绑定了抓取物品:
现在要移动物品:
if(PhysicsHandle && PhysicsHandle->GrabbedComponent)
{
PhysicsHandle->SetTargetLocation(GetLineEnd());
}
PhysicsHandle ->ReleaseComponent();
一直抓取着,在TickComponent中
// Called every frame
void UGrabber::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
if (PhysicsHandle&&PhysicsHandle->GrabbedComponent)
{
PhysicsHandle->SetTargetLocation(GetLineEnd());
}
}
void UGrabber::Grab()
{
UE_LOG(LogTemp, Warning, TEXT("Grab action is pressed!"));
FHitResult Hit = LineTrace();
UPrimitiveComponent* ComponentToGrab = Hit.GetComponent();
if (Hit.GetActor() && PhysicsHandle)
{
UE_LOG(LogTemp, Warning, TEXT("Grab!"));
//PhysicsHandle->GrabComponent(ComponentToGrab, NAME_None, ComponentToGrab->GetOwner()->GetActorLocation(), true);
PhysicsHandle->GrabComponentAtLocationWithRotation(ComponentToGrab, NAME_None, ComponentToGrab->GetOwner()->GetActorLocation(), GetOwner()->GetActorRotation());
}
}
void UGrabber::Release()
{
UE_LOG(LogTemp, Error, TEXT("Grab action is released!"));
if (PhysicsHandle)
{
PhysicsHandle->ReleaseComponent();
}
}