如何从另一个类启动角色 我创建了一个启动程序的C++类,它是一个立方体静态网格组件和一个Ubox组件的编译。现在,一旦角色与点击框重叠,它就会触发ALaunchPad::OnBoxBeginOverlap中的任何内容。我现在试图告诉大家,当角色与UBox重叠时,在空中发射它们,类似于蓝图的“LaunchCharacter”节点

如何从另一个类启动角色 我创建了一个启动程序的C++类,它是一个立方体静态网格组件和一个Ubox组件的编译。现在,一旦角色与点击框重叠,它就会触发ALaunchPad::OnBoxBeginOverlap中的任何内容。我现在试图告诉大家,当角色与UBox重叠时,在空中发射它们,类似于蓝图的“LaunchCharacter”节点,c++,unreal-engine4,C++,Unreal Engine4,LaunchPad.cpp void ALaunchPad::OnBoxBeginOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) { GEngine->AddOnScreenDebugMe

LaunchPad.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);

}
发射台

// 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();

};


目前,我收到一个“非静态成员引用必须是相对于特定对象的,并且它不会编译”。有什么想法吗?

其他参与者
投射到
字符
上,然后调用其
启动字符
方法:

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);
    }

}
void ALaunchPad::OnBoxBeginOverlap(UPrimitiveComponent*OverlappedComp,AActor*OtherActor,
UPrimitiveComponent*OtherComp,int32 OtherBodyIndex,bool bFromSweep,
常量FHitResult和扫描结果)
{
GEngine->AddOnScreenDebugMessage(-1,15.0f,FColor::Yellow,文本(“角色启动!”);
ACharacter*OtherCharacter=Cast(OtherActor);
if(OtherCharacter!=nullptr)
{
OtherCharacter->LaunchCharacter(FVector(0,0,速度),false,true);
}
}