11715人加入学习
(26人评价)
【旧版】Unreal基本知识案例 - 密室逃脱

旧版课程,制作完成于2017-01-11

价格 免费

射线检测:

FHitResult Hit;

GetWorld()->LineTraceSingleByObjectType

(

Hit,

Start,

End,

FCollisionObjectQueryParams(ECollisionChannel::ECC_PhysicsBody),

FCollisionQueryParam(FName(TEXT("")), false, GetOwner())

);

[展开全文]

射线检测:有起点有方向有距离

ECC_PhysicsBody 物理物体

细节面板上的 Physics ,勾选 Simulate Physics 才会触发碰撞,

射线触发一定要勾选上 细节面板上的Physics下的 Simulate Physics 才会触发

 

Grabber.cpp

#include "Grabber.h"
#include "Engine/World.h"
#include "DrawDebugHelpers.h"


UGrabber::UGrabber()
{
	PrimaryComponentTick.bCanEverTick = true;
}


void UGrabber::BeginPlay()
{
	Super::BeginPlay();
}


void UGrabber::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

	FVector Start;
	FRotator ViewRotator;
	GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(Start, ViewRotator);

	FVector End = Start + ViewRotator.Vector() * 100; // ViewRotator.Vector() 视野的正中心 前方 100cm

	//DrawDebugLine(GetWorld(), Start, End, FColor(255, 0, 0), false, 0, 0, 10);

	FHitResult Hit;
	GetWorld()->LineTraceSingleByObjectType(
		Hit,
		Start,
		End,
		FCollisionObjectQueryParams(ECollisionChannel::ECC_PhysicsBody),
		FCollisionQueryParams(FName(TEXT("")), false, GetOwner())
	);
	AActor* Actor = Hit.GetActor();
	if (Actor != nullptr)
	{
		UE_LOG(LogTemp, Warning, TEXT("Line Hit:%s"), *Actor->GetName());
	}
}

 

[展开全文]

FVector Start;
    FRotator ViewRotator;
    GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(Start, ViewRotator);

    FVector End = Start + ViewRotator.Vector()*100;

    DrawDebugLine(GetWorld(), Start, End, FColor(255, 0, 0), false, 0, 0, 10);

[展开全文]

当Simulate Physics勾选完后,物体受模拟物理效果影响,如重力。

Simulation Generates Hit Events 是"当此对象在物理模拟中发生碰撞时是否发送命中事件"

[展开全文]

授课教师

SiKi学院老师

课程特色

图文(2)
视频(37)