RPG4.设置角色输入

这一篇是进行玩家移动和视角移动的介绍。

1.在玩家内进行移动覆写

virtual void SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) override;

2.创建增强输入资产的变量创建

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "CharacterData", meta = (AllowPrivateAccess = "true"))UDA_InputConfig* InputConfigDataAsset;

3.进行移动和视角移动函数的创建

void Input_Move(const FInputActionValue& InputActionValue);void Input_Look(const FInputActionValue& InputActionValue);

4.在SetupPlayerInputComponent函数内进行输入绑定

//设置玩家输入组件
void AXMBCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{//添加映射上下文checkf(InputConfigDataAsset, TEXT("Forgot to assign a valid data as input config"))//获取本地玩家ULocalPlayer* LocalPlayer = GetController<APlayerController>()->GetLocalPlayer();//获取增强输入子系统UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(LocalPlayer);check(Subsystem);//添加映射上下文Subsystem->AddMappingContext(InputConfigDataAsset->DefaultMappingContext,0);//获取角色输入组件并绑定输入动作UXMBWarriorInputComponent* WarriorInputComponent = CastChecked<UXMBWarriorInputComponent>(PlayerInputComponent);WarriorInputComponent->BindNativeInputAction(InputConfigDataAsset,XMBGameplayTags::InputTag_Move, ETriggerEvent::Triggered,this,&ThisClass::Input_Move);WarriorInputComponent->BindNativeInputAction(InputConfigDataAsset,XMBGameplayTags::InputTag_Look, ETriggerEvent::Triggered,this,&ThisClass::Input_Look);}

5.对Move函数进行设置

void AXMBCharacter::Input_Move(const FInputActionValue& InputActionValue)
{//获取移动向量const FVector2D MovementVector = InputActionValue.Get<FVector2D>();//获取移动旋转const FRotator MovementRotation(0.f, Controller->GetControlRotation().Yaw, 0.f);//处理前后移动if (MovementVector.Y != 0.f){const FVector ForwardDirection = MovementRotation.RotateVector(FVector::ForwardVector);AddMovementInput(ForwardDirection, MovementVector.Y);}//处理左右移动if (MovementVector.X != 0.f){const FVector RightDirection = MovementRotation.RotateVector(FVector::RightVector);AddMovementInput(RightDirection, MovementVector.X);}}

6.对视角移动函数进行设置

void AXMBCharacter::Input_Look(const FInputActionValue& InputActionValue)
{const FVector2D LookAxisVector = InputActionValue.Get<FVector2D>();if (LookAxisVector.X != 0.f){AddControllerYawInput(LookAxisVector.X);}if (LookAxisVector.Y != 0.f){AddControllerPitchInput(LookAxisVector.Y);}
}

7.打开引擎,进入角色蓝图,细节面板搜索data,更换成自己的dataasset

#include "Character/XMBCharacter.h"
#include "Components/CapsuleComponent.h"
#include "GameFramework/SpringArmComponent.h"
#include "Camera/CameraComponent.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "EnhancedInputSubsystems.h"
#include "Data/Input/DA_InputConfig.h"
#include "Components/Input/XMBWarriorInputComponent.h"
#include "XMBGameplayTags.h"#include "XMBDebugHelper.h"AXMBCharacter::AXMBCharacter()
{GetCapsuleComponent()->InitCapsuleSize(42.f, 96.f);bUseControllerRotationPitch = false;bUseControllerRotationYaw = false;bUseControllerRotationRoll = false;CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));CameraBoom->SetupAttachment(GetRootComponent());CameraBoom->TargetArmLength = 300.0f;CameraBoom->SocketOffset = FVector(0.0f, 55.0f, 60.0f);CameraBoom->bUsePawnControlRotation = true;FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName);FollowCamera->bUsePawnControlRotation = false;GetCharacterMovement()->bOrientRotationToMovement = true;GetCharacterMovement()->RotationRate = FRotator(0.0f, 550.0f, 0.0f);GetCharacterMovement()->MaxWalkSpeed = 400.f;GetCharacterMovement()->BrakingDecelerationWalking = 2000.f;}void AXMBCharacter::BeginPlay()
{Super::BeginPlay();Debug::Print(FString::Printf(TEXT("XMBCharacter::BeginPlay")));
}//设置玩家输入组件
void AXMBCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{//添加映射上下文checkf(InputConfigDataAsset, TEXT("Forgot to assign a valid data as input config"))//获取本地玩家ULocalPlayer* LocalPlayer = GetController<APlayerController>()->GetLocalPlayer();//获取增强输入子系统UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(LocalPlayer);check(Subsystem);//添加映射上下文Subsystem->AddMappingContext(InputConfigDataAsset->DefaultMappingContext,0);//获取角色输入组件并绑定输入动作UXMBWarriorInputComponent* WarriorInputComponent = CastChecked<UXMBWarriorInputComponent>(PlayerInputComponent);WarriorInputComponent->BindNativeInputAction(InputConfigDataAsset,XMBGameplayTags::InputTag_Move, ETriggerEvent::Triggered,this,&ThisClass::Input_Move);WarriorInputComponent->BindNativeInputAction(InputConfigDataAsset,XMBGameplayTags::InputTag_Look, ETriggerEvent::Triggered,this,&ThisClass::Input_Look);}void AXMBCharacter::Input_Move(const FInputActionValue& InputActionValue)
{//获取移动向量const FVector2D MovementVector = InputActionValue.Get<FVector2D>();//获取移动旋转const FRotator MovementRotation(0.f, Controller->GetControlRotation().Yaw, 0.f);//处理前后移动if (MovementVector.Y != 0.f){const FVector ForwardDirection = MovementRotation.RotateVector(FVector::ForwardVector);AddMovementInput(ForwardDirection, MovementVector.Y);}//处理左右移动if (MovementVector.X != 0.f){const FVector RightDirection = MovementRotation.RotateVector(FVector::RightVector);AddMovementInput(RightDirection, MovementVector.X);}// if (MovementVector.Z != 0.f)// {// 	const FVector RightDirection = MovementRotation.RotateVector(FVector::UpVector);//// 	AddMovementInput(RightDirection, MovementVector.Z);// }}void AXMBCharacter::Input_Look(const FInputActionValue& InputActionValue)
{const FVector2D LookAxisVector = InputActionValue.Get<FVector2D>();if (LookAxisVector.X != 0.f){AddControllerYawInput(LookAxisVector.X);}if (LookAxisVector.Y != 0.f){AddControllerPitchInput(LookAxisVector.Y);}
}
// Fill out your copyright notice in the Description page of Project Settings.#pragma once#include "CoreMinimal.h"
#include "InputActionValue.h"
#include "Character/CharacterBase.h"
#include "XMBCharacter.generated.h"class UDA_InputConfig;
class UCameraComponent;
class USpringArmComponent;
struct FInputActionValue;
/*** */
UCLASS()
class ARPG_GRIVITY_API AXMBCharacter : public ACharacterBase
{GENERATED_BODY()
public:AXMBCharacter();protected:virtual void BeginPlay() override;virtual void SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) override;private:UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Camera", meta = (AllowPrivateAccess = "true"))USpringArmComponent* CameraBoom;UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Camera", meta = (AllowPrivateAccess = "true"))UCameraComponent* FollowCamera;//UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "CharacterData", meta = (AllowPrivateAccess = "true"))UDA_InputConfig* InputConfigDataAsset;void Input_Move(const FInputActionValue& InputActionValue);void Input_Look(const FInputActionValue& InputActionValue);};

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/903659.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

[实战] Petalinux驱动开发以及代码框架解读

目录 Petalinux驱动开发以及代码框架解读一、引言二、步骤2.1 创建PetaLinux工程2.2 配置硬件描述文件2.3 设备树配置2.4 建立驱动框架2.5 编辑 .bb 文件2.6 编写驱动文件2.7 编写 Makefile2.8 验证配方配置2.9 集成驱动到 RootFS2.10 全系统编译与部署2.11 启动验证 三、框架解…

[特殊字符] 开发工作高内存占用场景下,Windows 内存压缩机制是否应该启用?实测分析与优化建议

在日常开发中&#xff0c;我们往往需要同时运行多个高占用内存的工具&#xff0c;例如&#xff1a; IntelliJ IDEA VMware 虚拟机 多个 Java 后端程序 这些应用程序非常“吃内存”&#xff0c;轻松就能把 16GB、甚至 24GB 的物理内存用满。那么&#xff0c;Windows 的“内存…

嵌入式学习笔记 - HAL_xxx_MspInit(xxx);函数

使用cubeMX生成的HAL库函数中&#xff0c;所有外设的初始化函数HAL_xxx_Init(&xxxHandle)中都存在有此调用函数HAL_xxx_MspInit(xxx)&#xff0c;此调用函数其实是对各外设模块比如UART&#xff0c;I2C等控制器使用的的底层硬件进行初始化&#xff0c;包括时钟&#xff0c;…

Nginx — http、server、location模块下配置相同策略优先级问题

一、配置优先级简述 在 Nginx 中&#xff0c;http、server、location 模块下配置相同策略时是存在优先级的&#xff0c;一般遵循 “范围越小&#xff0c;优先级越高” 的原则&#xff0c;下面为你详细介绍&#xff1a; 1. 配置继承关系 http 块&#xff1a;作为全局配置块&…

WPF之TextBlock控件详解

文章目录 1. TextBlock控件介绍2. TextBlock的基本用法2.1 基本语法2.2 在代码中创建TextBlock 3. TextBlock的常用属性3.1 文本内容相关属性3.2 字体相关属性3.3 外观相关属性3.4 布局相关属性 4. TextBlock文本格式化4.1 使用Run元素进行内联格式化4.2 其他内联元素 5. 处理长…

华为云loT物联网介绍与使用

&#x1f310; 华为云 IoT 物联网平台详解&#xff1a;构建万物互联的智能底座 随着万物互联时代的到来&#xff0c;物联网&#xff08;IoT&#xff09;已成为推动数字化转型的关键技术之一。华为云 IoT 平台&#xff08;IoT Device Access&#xff09;作为华为云的核心服务之…

AnimateCC教学:形状补间动画的代码实现

核心代码: var shape; var animationProps = {width: 50,height: 50,cornerRadius: 0,color: "#00FF00" }; function init() { shape = new createjs.Shape();shape.x = 200;shape.y = 150;stage.addChild(shape);// 初始绘制updateShape();// 设置补间动画createTw…

Android学习总结之Retrofit篇

1. 注解原理概述 在 Java 里&#xff0c;注解是一种元数据&#xff0c;它为代码提供额外信息但不影响程序的实际逻辑。注解可以在类、方法、字段等元素上使用&#xff0c;并且能在编译时、运行时通过反射机制被读取。Retrofit 充分利用了 Java 注解机制&#xff0c;通过自定义…

windows11 编译 protobuf-3.21.12 c++

下载 protobuf 包&#xff0c;本文使用 3.21.12 版本&#xff0c;Gitub下载链接&#xff1a; Github官网 , 网盘下载&#xff1a; 网盘 如果电脑环境没有安装 cmake 则需要安装&#xff0c;本文测试使用 cmake-3.25.1 版本&#xff0c; 下载地址&#xff1a;[camke-3.25.1] (…

Java继承中super的使用方法

super 关键字在 Java 中用于访问父类的成员&#xff08;包括字段、方法和构造函数&#xff09;。当你在子类中调用父类的方法或访问父类的成员变量时&#xff0c;super 是必不可少的工具。 &#x1f511; super 的基本用法 1. 调用父类的构造方法 在子类的构造方法中&#x…

网络安全之浅析Java反序列化题目

前言 这段时间做了几道Java反序列化题目&#xff0c;发现很多题目都是类似的&#xff0c;并且可以通过一些非预期gadget打进去&#xff0c;就打算总结一下常见的题目类型以及各种解法&#xff0c;并提炼出一般性的思维方法。 正文 分析入口点 拿到题目&#xff0c;有附件最…

动态规划问题,下降路径最小和(dp初始化问题,状态压缩),单词拆分(回溯法+剪枝+记忆化),substr函数

下降路径最小和 题目链接&#xff1a; 931. 下降路径最小和 - 力扣&#xff08;LeetCode&#xff09; 题目描述&#xff1a; 给你一个 n x n 的 方形 整数数组 matrix &#xff0c;请你找出并返回通过 matrix 的下降路径 的 最小和 。 下降路径 可以从第一行中的任何元素开…

大数据治理自动化与智能化实践指南:架构、工具与实战方案(含代码)

📝个人主页🌹:一ge科研小菜鸡-CSDN博客 🌹🌹期待您的关注 🌹🌹 一、引言:从人治到机治,数据治理正在进化 随着数据体量持续膨胀、数据场景复杂化,传统依赖人工规则的大数据治理方式已难以为继。企业在治理过程中面临: 数据质量问题激增,人工检测成本高 元数…

Golang - 实现文件管理服务器

先看效果&#xff1a; 代码如下&#xff1a; package mainimport ("fmt""html/template""log""net/http""os""path/filepath""strings" )// 配置根目录&#xff08;根据需求修改&#xff09; //var ba…

Linux-04-用户管理命令

一、useradd添加新用户: 基本语法: useradd 用户名:添加新用户 useradd -g 组名 用户:添加新用户到某个组二、passwd设置用户密码: 基本语法: passwd 用户名:设置用户名密码 三、id查看用户是否存在: 基本语法: id 用户名 四、su切换用户: 基本语法: su 用户名称:切换用…

Ollama 安装 QWen3 及配置外网访问指南

一、Ollama 安装 QWen3 安装步骤 首先尝试运行 QWen3 模型&#xff1a; ollama run qwen3 如果遇到版本不兼容错误&#xff08;Error 412&#xff09;&#xff0c;表示需要升级 Ollama&#xff1a; curl -fsSL https://ollama.com/install.sh | sh 验证版本&#xff1a; o…

高性能架构设计-数据库(读写分离)

一、高性能数据库简介 1.高性能数据库方式 读写分离&#xff1a;将访问压力分散到集群中的多个节点&#xff0c;没有分散存储压力 分库分表&#xff1a;既可以分散访问压力&#xff0c;又可以分散存储压力 2.为啥不用表分区 如果SQL不走分区键&#xff0c;很容易出现全表锁…

【Hive入门】Hive性能优化:执行计划分析EXPLAIN命令的使用

目录 1 EXPLAIN命令简介 1.1 什么是EXPLAIN命令&#xff1f; 1.2 EXPLAIN命令的语法 2 解读执行计划中的MapReduce阶段 2.1 执行计划的结构 2.2 Hive查询执行流程 2.3 MapReduce阶段的详细解读 3 识别性能瓶颈 3.1 数据倾斜 3.2 Shuffle开销 3.3 性能瓶颈识别与优化 4 总结 在大…

开源模型应用落地-qwen模型小试-Qwen3-8B-快速体验(一)

一、前言 阿里云最新推出的 Qwen3-8B 大语言模型,作为国内首个集成“快思考”与“慢思考”能力的混合推理模型,凭借其 80 亿参数规模及 128K 超长上下文支持,正在重塑 AI 应用边界。该模型既可通过轻量化“快思考”实现低算力秒级响应,也能在复杂任务中激活深度推理模式,以…

Kafka Producer的acks参数对消息可靠性有何影响?

1. acks0 可靠性最低生产者发送消息后不等待任何Broker确认可能丢失消息&#xff08;Broker处理失败/网络丢失时无法感知&#xff09;吞吐量最高&#xff0c;适用于允许数据丢失的场景&#xff08;如日志收集&#xff09; 2. acks1 (默认值) Leader副本确认模式生产者等待Le…