【发布时间】:2020-06-09 04:55:10
【问题描述】:
我是虚幻引擎的新手。我正在尝试创建一个基本游戏,您可以在其中控制球并滚动,尽量不要从管子之类的东西中掉出来。我的球是这样的:
PlayerBall.h
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "PlayerBall.generated.h"
UCLASS()
class ROLLINGBALL_API APlayerBall : public APawn
{
GENERATED_BODY()
public:
// Sets default values for this pawn's properties
APlayerBall();
UPROPERTY(VisibleAnywhere, Category="Mesh")
UStaticMeshComponent* Mesh;
UPROPERTY(VisibleAnywhere, Category="Camera")
class UCameraComponent* Camera;
protected:
// Called when the game starts or when spawned
void BeginPlay() override;
public:
// Called every frame
void Tick(float DeltaTime) override;
// Called to bind functionality to input
void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
};
PlayerBall.cpp
#include "PlayerBall.h"
#include "Camera/CameraComponent.h"
// Sets default values
APlayerBall::APlayerBall() {
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
const ConstructorHelpers::FObjectFinder<UStaticMesh> SphereRef(TEXT("StaticMesh'/Game/StarterContent/Shapes/Shape_Sphere.Shape_Sphere'"));
Mesh->SetStaticMesh(SphereRef.Object);
Mesh->SetSimulatePhysics(true);
Mesh->SetEnableGravity(true);
SetRootComponent(Mesh);
Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
Camera->SetRelativeLocation(FVector(-500.0f, 0.0f, 0.0f));
Camera->SetupAttachment(RootComponent);
AutoPossessPlayer = EAutoReceiveInput::Player0;
}
// Called when the game starts or when spawned
void APlayerBall::BeginPlay() {
Super::BeginPlay();
}
// Called every frame
void APlayerBall::Tick(float DeltaTime) {
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void APlayerBall::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) {
Super::SetupPlayerInputComponent(PlayerInputComponent);
}
我还有一些其他的障碍物和地板。但是,我也想要一些障碍物,如果它击中你,就会杀死你。我想要APlayerBall 类中的某种方法,当它被击中时调用它,然后我可以检查被击中的actor 的类型。我能做些什么?我使用什么组件?n 我在文档中查找了一个小时,但找不到任何内容。
我尝试添加RecieveHit 方法,但是它说它不会从超类覆盖。我是这样添加的:
void ReceiveHit
(
class UPrimitiveComponent * MyComp,
AActor * Other,
class UPrimitiveComponent * OtherComp,
bool bSelfMoved,
FVector HitLocation,
FVector HitNormal,
FVector NormalImpulse,
const FHitResult & Hit
) override;
【问题讨论】:
标签: c++ unreal-engine4