c++ - 如何从另一个类 LaunchCharacter
问题描述
我创建了一个 LaunchPad actor C++ 类,它由一个 Cube 静态网格组件和一个 UBox 组件编译而成。到目前为止,一旦角色与命中框重叠,它就会触发 ALaunchPad::OnBoxBeginOverlap 内的任何内容。我目前正试图告诉当角色与 UBox 重叠时,它们会在空中启动它们,类似于蓝图的“LaunchCharacter”节点。
启动板.cpp
void ALaunchPad::OnBoxBeginOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("Character Launched!"));
Asgd240_1115350_core5Character::LaunchCharacter(FVector(0, 0, velocity), false, true);
}
启动板.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "LaunchPad.generated.h"
UCLASS()
class SGD240_1115350_CORE5_API ALaunchPad : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
ALaunchPad();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
void OnBoxBeginOverlap(UPrimitiveComponent * HitComp, AActor * OtherActor, UPrimitiveComponent * OtherComp, FVector NormalImpulse, const FHitResult & Hit);
UPROPERTY(VisibleAnywhere)
class UBoxComponent* Collide;
UFUNCTION()
void OnBoxBeginOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
UPROPERTY(EditAnywhere)
float velocity;
UFUNCTION()
void LaunchCharacter();
};
目前我收到一个'非静态成员引用必须相对于特定对象并且它不会编译。有任何想法吗?
解决方案
转换OtherActor
为ACharacter
然后调用它的LaunchCharacter
方法:
void ALaunchPad::OnBoxBeginOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
const FHitResult& SweepResult)
{
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("Character Launched!"));
ACharacter* OtherCharacter = Cast<ACharacter>(OtherActor);
if (OtherCharacter != nullptr)
{
OtherCharacter->LaunchCharacter(FVector(0, 0, velocity), false, true);
}
}
推荐阅读
- performance - Dart 计时器动态更改持续时间
- javascript - 我试图在 javascript 中自动填充一些计算过的用户输入......你能告诉我为什么这总是出现解析错误吗?
- c# - 没有使用 MVVM 的 ComboBox 项目的可视化
- azure - 如何增加 MS Azure Custom Vision 中测试图像的数量?
- f# - hk 的 F# 算法
- docker - 工作人员之间的 Docker Swarm 覆盖网络
- apache-spark - 如何将 Spark Stream 数据保存到文件
- php - Laravel:仅从用户表中获取具有“用户”角色的用户
- mysql - mysqldump 命令覆盖现有数据后恢复丢失的数据
- python - 将字符串 'GMT+5:30' 转换为时区(如 Aisa/Kolkata)而不在 python 中检查 datetime.datetime.now()