pawn控制行走和几何体放缩

官方例子上有错误,

那个摄像机应该是成员变量,才能在编辑器中显示出来,

总动员上的api比较老了,不适合,它们用的attachTo(根组件),现在已经改为SetupAttachment(根组件)了

_ourCamera->SetupAttachment(RootComponent);

_ourVisibleComponent->SetupAttachment(RootComponent);

 

其他的没什么好说的,输入应该用pawn类,而不是actor,

    virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;起作用

先上图,可以看到actor和camera和RootComponent的层级关系

设置输入关系是在编辑->项目设置->输入中,操作映射是一步一动,轴映射是连续动

 

上代码

mypawn.h

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "MyPawn.generated.h"

class UCameraComponent;

UCLASS()
class MYSPAWN_DOC_API AMyPawn : public APawn
{
    GENERATED_BODY()

public:
    // Sets default values for this pawn's properties
    AMyPawn();

protected:
    // Called when the game starts or when spawned
    virtual void BeginPlay() override;

public:    
    // Called every frame
    virtual void Tick(float DeltaTime) override;

    // Called to bind functionality to input
    virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;

public:

    UPROPERTY(EditAnywhere)
    USceneComponent* _ourVisibleComponent;
    UPROPERTY(EditAnywhere)
    UCameraComponent* _ourCamera;

public:
    //输入函数
    void move_XAxis(float axisValue);
    void move_YAxis(float axisValue);
    void startGrowing();
    void stopGrowing();

public:
    FVector _currentVelocity;
    bool _bGrowing;

};


mypawn.cpp

// Fill out your copyright notice in the Description page of Project Settings.


#include "MyPawn.h"
#include "camera/cameraComponent.h"
#include "components/inputComponent.h"

// Sets default values
AMyPawn::AMyPawn()
{
     // 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;
    //将该pawn设为由最小编号玩家控制
    AutoPossessPlayer = EAutoReceiveInput::Player0;

    //创建可附加内容的虚拟根组件
    RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
    //创建相机和可见对象
    _ourCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("ourCamera"));
    _ourVisibleComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("ourVisibleComponent"));

    //将相机和可见对象附加到根组件,偏移并旋转相机
    _ourCamera->SetupAttachment(RootComponent);
    _ourCamera->SetRelativeLocation(FVector(-250.0f, 0.0f, 250.0f));
    _ourCamera->SetRelativeRotation(FRotator(-45.0f, 0.0f, 0.0f));
    _ourVisibleComponent->SetupAttachment(RootComponent);

}

// Called when the game starts or when spawned
void AMyPawn::BeginPlay()
{
    Super::BeginPlay();
    
}

// Called every frame
void AMyPawn::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);

    //缩放大小
    float currentScale = _ourVisibleComponent->GetComponentScale().X;
    if (_bGrowing)
    {
        currentScale += DeltaTime;
    }
    else
    {
        currentScale -= DeltaTime;
    }

    //确认不低于其实大小,或者增大之前的两倍大小
    currentScale = FMath::Clamp(currentScale, 1.0f, 2.0f);
    _ourVisibleComponent->SetWorldScale3D(FVector(currentScale));

    //位置
    FVector newLocation = GetActorLocation() + _currentVelocity * DeltaTime;
    SetActorLocation(newLocation);

}

// Called to bind functionality to input
void AMyPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
    Super::SetupPlayerInputComponent(PlayerInputComponent);

    //按下或松开grow
    PlayerInputComponent->BindAction("Grow", IE_Pressed, this, &AMyPawn::startGrowing);
    PlayerInputComponent->BindAction("Grow", IE_Released, this, &AMyPawn::stopGrowing);

    //每帧响应MoveX, MoveY
    PlayerInputComponent->BindAxis("MoveX", this, &AMyPawn::move_XAxis);
    PlayerInputComponent->BindAxis("MoveY", this, &AMyPawn::move_YAxis);

}

void AMyPawn::move_XAxis(float axisValue)
{
    //以每秒100单位的速度前后移动
    _currentVelocity.X = FMath::Clamp(axisValue, -1.0f, 1.0f) * 100.0f;
}

void AMyPawn::move_YAxis(float axisValue)
{
    _currentVelocity.Y = FMath::Clamp(axisValue, -1.0f, 1.0f) * 100.0f;
}

void AMyPawn::startGrowing()
{
    _bGrowing = true;
}

void AMyPawn::stopGrowing()
{
    _bGrowing = false;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MATLAB PAWN是基于全局灵敏度分析算法PAWN的MATLAB实现的工具。它可以用于评估模型中参数对输出的敏感性。PAWN方法考虑整个模型输出分布来描述输出的不确定性,并与Sobol方法进行比较。Sobol方法是一种基于方差的敏感性分析方法,而PAWN方法使用了更全面的输出分布信息。通过应用PAWN方法,可以对模型中的参数进行排序,以确定哪些参数对模型输出的影响最大。此外,PAWN还提供了评估和比较参数排序结果的相关演变、收敛性和计算成本等方面的指标。[1,3]<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [PAWN Global Sensitivity Analysis algorithm:全局灵敏度分析算法PAWN的MATLAB实现-matlab开发](https://download.csdn.net/download/weixin_38734008/19196355)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [MATLAB全局敏感性分析(包括dynia、eet、fast、glue、pawn、rsa、vbsa方法)](https://download.csdn.net/download/qq_25262697/86952961)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [优化算法——全局灵敏度分析算法(PAWN )(Matlab代码实现)](https://blog.csdn.net/weixin_46039719/article/details/126429368)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值