UE学习记录part7
93、collision presets
展示简单碰撞
如果没有简单碰撞,可以添加
在运行时输入命令show collision能够更好的检测碰撞体
query collision才能检测物体间的碰撞,如果是physics collision,无法实现物体间的碰撞
如果是query collision和physics collision同时勾选,则可以实现物体间的block效果和物体间的物理交互效果(例如人能够踢飞石子)
或者例如对相机阻塞,但是对pawn不阻塞,就能实现暗门效果
94、overlap events
一个蓝图类下,不同组件可以设置不同的overlap事件,可以用在捡拾物品
95&96&97、delegates
删除蓝图overlap事件
----Item.h------
class USphereComponent;
UFUNCTION()
void OnSphereOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
UFUNCTION()
void OnSphereEndOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
---------Item.cpp--------
#include "Components/SphereComponent.h"
void AItem::BeginPlay()
{
Super::BeginPlay();
Sphere->OnComponentBeginOverlap.AddDynamic(this, &AItem::OnSphereOverlap);
Sphere->OnComponentEndOverlap.AddDynamic(this, &AItem::OnSphereEndOverlap);
}
void AItem::OnSphereOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
const FString OtherActorName = OtherActor->GetName();
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(1, 30.f, FColor::Red, OtherActorName);
}
}
void AItem::OnSphereEndOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
const FString OtherActorName = FString("Ending Overlap with: ") + OtherActor->GetName();
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(1, 30.f, FColor::Blue, OtherActorName);
}
}