【UE4/C++】绑定输入响应
2015-10-19 22:13
393 查看
.h
.cpp
关键点:
1.AutoPossessPlayer = EAutoReceiveInput::Player0;
2.SetupPlayerInputComponent.
对于BindAction和BindAxis的第一个参数,指的是在项目中设置的键盘映射(例子中的项目设定了一个键'Fire')
#include "GameFramework/Pawn.h" #include "MyPawn.generated.h" UCLASS() class PROJ3_API AMyPawn : public APawn { GENERATED_BODY() public: // Sets default values for this pawn's properties AMyPawn(); // Called when the game starts or when spawned virtual void BeginPlay() override; // Called every frame virtual void Tick( float DeltaSeconds ) override; // Called to bind functionality to input virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override; void Move_XAxis(float AxisValue); void Move_YAxis(float AxisValue); void StartGrowing(); void StopGrowing(); FVector CurrentVelocity; bool bGrowing; };
.cpp
#include "Proj3.h" #include "MyPawn.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; AutoPossessPlayer = EAutoReceiveInput::Player0; } // Called when the game starts or when spawned void AMyPawn::BeginPlay() { Super::BeginPlay(); } // Called every frame void AMyPawn::Tick( float DeltaTime ) { Super::Tick( DeltaTime ); } // Called to bind functionality to input void AMyPawn::SetupPlayerInputComponent(class UInputComponent* InputComponent) { Super::SetupPlayerInputComponent(InputComponent); InputComponent->BindAction("Fire", IE_Pressed, this, &AMyPawn::StartGrowing); InputComponent->BindAction("Fire", IE_Released, this, &AMyPawn::StopGrowing); InputComponent->BindAxis("MoveX", this, &AMyPawn::Move_XAxis); InputComponent->BindAxis("MoveY", this, &AMyPawn::Move_YAxis); } void AMyPawn::Move_XAxis(float AxisValue) { 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; }
关键点:
1.AutoPossessPlayer = EAutoReceiveInput::Player0;
2.SetupPlayerInputComponent.
对于BindAction和BindAxis的第一个参数,指的是在项目中设置的键盘映射(例子中的项目设定了一个键'Fire')
相关文章推荐
- UE4 发布HTML5要点 (上)
- UE4中的AI解析1
- UE4 AI浅析-shooterGame中的AI为例
- 如何在C++中创建可被Blueprint调用的全局函数
- UE4 中的人工智能解析—ShooterGame为例
- Unreal Enginer4特性介绍-牛B闪闪的UE4
- Blueprint编译过程
- UE4在VS2013中各个编译配置代表意义
- UE4的JSON读写方式<一>
- UE4.5.0的Kinect插件(Plugin)<一>
- UE4.5.0的Kinect插件(Plugin)---插件使用说明<二>
- UE4的JSON读写方式<二>
- 热烈庆祝UE4完全免费Free---GitHub上源码的关联方法
- Kinect舒适区范围--UE4 的Blueprint测试范例
- 虚幻引擎的热键说明
- UE4制作插件的插件神器pluginCreator
- 关卡原型制作思路
- 【UE4/C++】宏的使用
- 【UNREAL ENGINE 游戏开发】开篇之UE4的BLUEPRINT(蓝图)与C++(新童鞋必看)
- ue4同步填坑