问题遇到的现象和发生背景
UE4 C++
使用addforce函数时,可以生成解决方案,但是在ue4按下模拟运行时,先是卡一下啊,然后闪退,再报错。
遇到的现象和发生背景,请写出第一个错误信息
用代码块功能插入代码,请勿粘贴截图。 不用代码块回答率下降 50%
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Mycube.generated.h"
UCLASS()
class TEST_API AMycube : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
///
/// 声明模型变量
///
UPROPERTY(EditAnywhere,Category="ActorMeshCompoment")
UStaticMeshComponent* StaticMesh;
///
/// 位置信息
///
UPROPERTY(EditInstanceOnly, BlueprintReadWrite, Category = "MyValues")//场景中可见
FVector InitialLocation;//初始位置
///
/// 使用xxx功能吗?
///
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyValues")
bool use_InitialLocation;//使用初始位置吗
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyValues")
bool Use_World;//使用世界坐标吗?
///
/// 移动和旋转方向
///
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyValues")
FVector Initial_Direction;//移动方向
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyValues")
FRotator Initial_Rotation;//旋转方向
///
/// 力和扭矩
///
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyValues")
FVector InitialForce;//力
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyValues")
FVector InitialTorque;//扭矩
protected:
AMycube();
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
};
// Fill out your copyright notice in the Description page of Project Settings.
#include "Mycube.h"
#include "Components/StaticMeshComponent.h"
// Sets default values
AMycube::AMycube()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
AActor::PrimaryActorTick.bCanEverTick = true;
StaticMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MyMesh"));//创建默认子物体<类型>(名字)
//设置初始位置
InitialLocation = FVector(-100,350,420);
//设置方向
Initial_Direction = FVector(1, 0, 0);
//设置旋转
Initial_Rotation = FRotator(90, 0, 0);
//设置力和扭矩
InitialForce = FVector(0);
InitialTorque = FVector(0);
}
// Called when the game starts or when spawned
void AMycube::BeginPlay()
{
Super::BeginPlay();
if (use_InitialLocation) {
SetActorLocation(InitialLocation);
}
StaticMesh->AddForce(InitialForce, TEXT("NAME_None"), false);
//StaticMesh->AddTorque(InitialTorque);
}
// Called every frame
void AMycube::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
FHitResult HitResult;//声明变量
/*if (Use_World) {//根据世界坐标移动
AddActorWorldOffset(Initial_Direction, true, &HitResult);//添加对象移动/移动式是否开启扫描/扫描(碰撞)结果
AddActorWorldRotation(Initial_Rotation);
}
else {
AddActorLocalOffset(Initial_Direction, true, &HitResult);//添加对象移动/移动式是否开启扫描/扫描(碰撞)结果
AddActorLocalRotation(Initial_Rotation);
}*/
/*if (HitResult.bBlockingHit) {
UE_LOG(LogTemp, Warning, TEXT("@@f Hit@:x=%f,y=%f,z=%f"),HitResult.Location.X, HitResult.Location.Y, HitResult.Location.Z);
}*/
if (HitResult.bBlockingHit) {
UE_LOG(LogTemp, Warning, TEXT("@@s Hit@:x=%s,y=%s,z=%s"),*FString::SanitizeFloat(HitResult.Location.X), *FString::SanitizeFloat(HitResult.Location.Y),* FString::SanitizeFloat(HitResult.Location.Z));
}
}