上一篇博客里 咱已經(jīng)在TouchBegan里面獲取了物體 還是射線(xiàn)獲取滴。
思路:接下來(lái)。在TouchMove里面 再發(fā)射一條射線(xiàn) 然后。打中物體就按打中那里的坐標(biāo)算 沒(méi)打中就按射線(xiàn)的end坐標(biāo)算
這個(gè)坐標(biāo)減去物體的坐標(biāo) 得到一個(gè)FVector 這個(gè)物體SetActorRotation就闊以轉(zhuǎn)了
來(lái)。完整馬
FCollisionQueryParams Trace(FName(TEXT("TRACE")), true, GetPawn());//建立射線(xiàn) Trace.bReturnPhysicalMaterial = false; Trace.bTraceComplex = true; Trace.AddIgnoredActor(GetPawn());//忽略默認(rèn)人物棋子 FHitResult Hit(ForceInit);//這個(gè)hit裝反饋信息 UWorld*world = GetWorld(); if (world) { ECollisionChannel CollisionChannel= ECC_Pawn;//貌似是個(gè)忽略Actor 。 world->LineTraceSingleByChannel(Hit, lbeg, lend, CollisionChannel, Trace); if (Hit.GetActor()) { FVector Dir = Hit.Location - Sphere->GetActorLocation();//如果打中實(shí)物 就實(shí)物坐標(biāo)減去物體坐標(biāo)得到一個(gè)方向FVector Dir.Z = 0; Sphere->SetActorRotation(Dir.Rotation()); } else if (!Hit.GetActor()) { FVector Dir = lend - Sphere->GetActorLocation();//沒(méi)打中東西就按鼠標(biāo)射線(xiàn)的末端算咯。。 Sphere->SetActorRotation(Dir.Rotation()); } }嗯。就是醬紫
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注