当前位置: 首页 > news >正文

UE5 第一人称示例代码阅读0 UEnhancedInputComponent

UEnhancedInputComponent使用流程

  • 我的总结
  • 示例分析
    • first
    • then
    • and then
    • finally&代码
      • 关于键盘输入XYZ

我的总结

这个东西是一个对输入进行控制的系统,看了一下第一人称例子里,算是看明白了,但是感觉这东西使用起来有点绕,特此梳理一下
总结来说是这样的 一个context应该对应了一种character,一个context管理几个action,然后就是先要在面板里创建这些东西,最后还需要在代码里去addMappingContext一下以及bindaction一下

示例分析

在这里插入图片描述
首先注意看这里有两个input mapping context

first

也就是你要先创建一个IMC
在这里插入图片描述在这里插入图片描述
点击查看后,各自mapping了几个action,default对应jump move look是控制主人物的
shoot是控制weapon的

then

也就是说你接下来应该创建action,并且在mapping这里绑定好对应的键位和action

and then

这个context能识别key然后映射到action了,接下来就是把context和character绑定好
在这里插入图片描述
找了半天,shoot的绑定在这里

在这里插入图片描述
其他三个比较明显,就在firstperson这
在这里插入图片描述在这里插入图片描述

finally&代码

这里就到了代码绑定阶段了
看头文件FirstPersonCharacter.h
定义那几个action以及对应要执行的函数,这里我看他action的名字和character的input里确实写得一模一样,这里应该哪里有反射啥的吧
另外就是context部分
在这里插入图片描述
在这里插入图片描述

关于键盘输入XYZ

然后这个XY方向啥的就参考第一人称和第三人称的用法好了
类似这个
在这里插入图片描述

// Copyright Epic Games, Inc. All Rights Reserved.#pragma once#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "Logging/LogMacros.h"
#include "FirstPersonCharacter.generated.h"class UInputComponent;
class USkeletalMeshComponent;
class UCameraComponent;
class UInputAction;
class UInputMappingContext;
struct FInputActionValue;DECLARE_LOG_CATEGORY_EXTERN(LogTemplateCharacter, Log, All);UCLASS(config=Game)
class AFirstPersonCharacter : public ACharacter
{GENERATED_BODY()/** Pawn mesh: 1st person view (arms; seen only by self) */UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Mesh, meta = (AllowPrivateAccess = "true"))USkeletalMeshComponent* Mesh1P;/** First person camera */UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))UCameraComponent* FirstPersonCameraComponent;/** Jump Input Action */UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true"))UInputAction* JumpAction;/** Move Input Action */UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true"))UInputAction* MoveAction;public:AFirstPersonCharacter();protected:virtual void BeginPlay();public:/** Look Input Action */UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))class UInputAction* LookAction;protected:/** Called for movement input */void Move(const FInputActionValue& Value);/** Called for looking input */void Look(const FInputActionValue& Value);protected:// APawn interfacevirtual void SetupPlayerInputComponent(UInputComponent* InputComponent) override;// End of APawn interfacepublic:/** Returns Mesh1P subobject **/USkeletalMeshComponent* GetMesh1P() const { return Mesh1P; }/** Returns FirstPersonCameraComponent subobject **/UCameraComponent* GetFirstPersonCameraComponent() const { return FirstPersonCameraComponent; }};

然后是实现
主要就是调用 EnhancedInputComponent->BindAction这个把对应函数绑定上去就好了

// Copyright Epic Games, Inc. All Rights Reserved.#include "FirstPersonCharacter.h"
#include "FirstPersonProjectile.h"
#include "Animation/AnimInstance.h"
#include "Camera/CameraComponent.h"
#include "Components/CapsuleComponent.h"
#include "Components/SkeletalMeshComponent.h"
#include "EnhancedInputComponent.h"
#include "EnhancedInputSubsystems.h"
#include "InputActionValue.h"
#include "Engine/LocalPlayer.h"DEFINE_LOG_CATEGORY(LogTemplateCharacter);//
// AFirstPersonCharacterAFirstPersonCharacter::AFirstPersonCharacter()
{// Set size for collision capsuleGetCapsuleComponent()->InitCapsuleSize(55.f, 96.0f);// Create a CameraComponent	FirstPersonCameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("FirstPersonCamera"));FirstPersonCameraComponent->SetupAttachment(GetCapsuleComponent());FirstPersonCameraComponent->SetRelativeLocation(FVector(-10.f, 0.f, 60.f)); // Position the cameraFirstPersonCameraComponent->bUsePawnControlRotation = true;// Create a mesh component that will be used when being viewed from a '1st person' view (when controlling this pawn)Mesh1P = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("CharacterMesh1P"));Mesh1P->SetOnlyOwnerSee(true);Mesh1P->SetupAttachment(FirstPersonCameraComponent);Mesh1P->bCastDynamicShadow = false;Mesh1P->CastShadow = false;//Mesh1P->SetRelativeRotation(FRotator(0.9f, -19.19f, 5.2f));Mesh1P->SetRelativeLocation(FVector(-30.f, 0.f, -150.f));}void AFirstPersonCharacter::BeginPlay()
{// Call the base class  Super::BeginPlay();
} Inputvoid AFirstPersonCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{	// Set up action bindingsif (UEnhancedInputComponent* EnhancedInputComponent = Cast<UEnhancedInputComponent>(PlayerInputComponent)){// JumpingEnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Started, this, &ACharacter::Jump);EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Completed, this, &ACharacter::StopJumping);// MovingEnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &AFirstPersonCharacter::Move);// LookingEnhancedInputComponent->BindAction(LookAction, ETriggerEvent::Triggered, this, &AFirstPersonCharacter::Look);}else{UE_LOG(LogTemplateCharacter, Error, TEXT("'%s' Failed to find an Enhanced Input Component! This template is built to use the Enhanced Input system. If you intend to use the legacy system, then you will need to update this C++ file."), *GetNameSafe(this));}
}void AFirstPersonCharacter::Move(const FInputActionValue& Value)
{// input is a Vector2DFVector2D MovementVector = Value.Get<FVector2D>();if (Controller != nullptr){// add movement AddMovementInput(GetActorForwardVector(), MovementVector.Y);AddMovementInput(GetActorRightVector(), MovementVector.X);}
}void AFirstPersonCharacter::Look(const FInputActionValue& Value)
{// input is a Vector2DFVector2D LookAxisVector = Value.Get<FVector2D>();if (Controller != nullptr){// add yaw and pitch input to controllerAddControllerYawInput(LookAxisVector.X);AddControllerPitchInput(LookAxisVector.Y);}
}

相关文章:

UE5 第一人称示例代码阅读0 UEnhancedInputComponent

UEnhancedInputComponent使用流程 我的总结示例分析firstthenand thenfinally&代码关于键盘输入XYZ 我的总结 这个东西是一个对输入进行控制的系统&#xff0c;看了一下第一人称例子里&#xff0c;算是看明白了&#xff0c;但是感觉这东西使用起来有点绕&#xff0c;特此梳…...

如何在Linux下安装和配置Docker

文章目录 安装前的准备在Debian/Ubuntu上安装Docker添加Docker仓库安装Docker验证安装 在CentOS/RHEL上安装Docker安装必要的软件包设置Docker仓库安装Docker启动Docker服务 Docker的基本使用拉取一个镜像运行一个容器 配置Docker创建Docker目录使用非root用户运行Docker 结语 …...

apisix的原理及作用,跟spring cloud gateway有什么区别?

apache APISIX 是一个高性能、可扩展的开源 API 网关&#xff0c;它主要用于处理 API 请求、流量管理、安全控制和服务治理。APISIX 可以将复杂的服务架构中的不同服务通过统一的网关来进行管理和监控&#xff0c;为微服务架构提供了便捷的流量入口管理方式。 APISIX 的原理 …...

华为HarmonyOS实现实时语音识别转文本

场景介绍 将一段音频信息&#xff08;短语音模式不超过60s&#xff0c;长语音模式不超过8h&#xff09;转换为文本&#xff0c;音频信息可以为pcm音频文件或者实时语音。 开发步骤 在使用语音识别时&#xff0c;将实现语音识别相关的类添加至工程。 import { speechRecogni…...

DIY可视化-uniapp悬浮菜单支持拖动、吸附-代码生成器

在Uniapp中&#xff0c;悬浮菜单支持拖动和吸附功能&#xff0c;可以为用户带来更加灵活和便捷的操作体验。以下是对这两个功能的详细解释&#xff1a; 悬浮菜单支持拖动 提高用户体验&#xff1a;用户可以根据自己的需要&#xff0c;将悬浮菜单拖动到屏幕上的任意位置&#x…...

HTTP cookie 与 session

一.Cookie 定义&#xff1a; 是服务器发送到用户浏览器并保存在浏览器上的一小块数据&#xff0c; 它会在浏览器之后向同一服务器再次发起请求时被携带并发送到服务器上。 通常&#xff0c; 它用于告知服务端两个请求是否来自同一浏览器&#xff0c; 如保持用户的登录状态、 …...

智慧停车场导航系统架构及反向寻车系统解决方案

一、系统概述&#xff1a; 随着当前室内定位导航技术在大型公共场所如政务中心、商业综合体、车站中的应用越来越多&#xff0c;人们对智慧停车场的需求也日益凸显出来&#xff0c;并且智慧停车场对大型公共场所智慧化的整体建设起到重要作用。如何更有效提高停车效率&#xf…...

【小程序上传图片封装2024,支持多图,带进度,上传头像】

import config from ./config;// 支持多图&#xff0c;显示进度 export function uploadImages(count 1, sourceType, onLoading null, showProgress false, fileKey file) {return new Promise((resolve, reject) > {wx.chooseMedia({count: count, // 可以选择的图片数…...

[A-14]ARMv8/ARMv9-Memory-内存模型的类型(Device Normal)

ver0.1 [看前序文章有惊喜。] 前言 前面花了很大的精力把ARM构建的VMSA中的几个核心的议题给大家做了介绍,相信大家已经能够理解并掌握ARM的内存子系统的工作原理大致框架。接下来我们会规划一些文章,对ARM内存子系统的一些细节做一下介绍,使ARM的内存子系统更加的丰满。本…...

驾校管理系统|基于java和小程序的驾校管理系统设计与实现(源码+数据库+文档)

驾校管理系统平台 目录 基于java和小程序的驾校管理系统设计与实现 一、前言 二、系统设计 三、系统功能设计 四、数据库设计 五、核心代码 六、论文参考 七、最新计算机毕设选题推荐 八、源码获取&#xff1a; 博主介绍&#xff1a;✌️大厂码农|毕设布道师&#…...

@Mapper使用中遇到的问题解法汇总

最近终于有时间写点代码相关的文章了&#xff0c;工作真的太忙了&#xff0c;果然又要测试又要开发的人最&#x1f402;&#x1f434;。 1.查询数据库有数据&#xff0c;但是代码中写select语句的时候查出为null Select("SELECT * FROM xx_manager order by id limit 1&q…...

深度学习:YOLO V3 网络架构解析

引言 YOLO V3&#xff08;You Only Look Once Version 3&#xff09;是YOLO系列算法的第三个版本&#xff0c;相比之前的版本&#xff0c;它在多个方面进行了优化和改进&#xff0c;不仅提升了检测精度&#xff0c;还保持了较快的检测速度。本文将详细介绍YOLO V3的主要改进以…...

SpringCloudAlibaba-Sentinel-熔断与限流

版本说明 <spring.boot.version>3.2.0</spring.boot.version> <spring.cloud.version>2023.0.0</spring.cloud.version> <spring.cloud.alibaba.version>2023.0.1.2</spring.cloud.alibaba.version>是什么 能干嘛 面试题 服务雪崩 安装使…...

mysql中的mvcc理解

是什么&#xff1a;MVCC指的是在读已提交、可重复读这两种隔离级别下的事务在执行普通的select操作时&#xff0c;访问记录的版本链的过程&#xff0c;可以使不同事务的读写操作并发执行&#xff0c;提高性能。 MVCC 隐藏字段 undo log 版本链 ReadView 1.隐藏字段&#xf…...

ETF申购赎回指南:详解注意事项与低费率券商推荐!

​ETF 申购&赎回 ETF申购赎回是个啥业务&#xff1f; 01 ETF申购、赎回是一种交易委托方式&#xff0c;指投资者通过申购方式(买入方向)获得ETF份额&#xff0c;通过赎回的方式&#xff08;卖出方向&#xff09;换掉/卖出ETF份额。ETF申购&#xff0c;通常是通过一篮子成…...

List<T>属性和方法使用

//author&#xff1a;shark_ddd using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;//使用函数来减少长度namespace List_T {class Student{public string Name { get; set; }public int Age { get; set; …...

记一次:使用使用Dbeaver连接Clickhouse

前言&#xff1a;使用了navicat连接了clickhouse我感觉不太好用&#xff0c;就整理了一下dbeaver连接 0、使用Navicat连接clickhouse 测试连接 但是不能双击打开&#xff0c;可是使用命令页界面&#xff0c;右键命令页界面&#xff0c;然后可以用sql去测试 但是不太好用&#…...

Java面向对象编程进阶(四)

Java面向对象编程进阶&#xff08;四&#xff09; 一、equals()方法的使用二、toString()方法的使用三、复习 一、equals()方法的使用 适用性&#xff1a;任何引用数据都可以使用。 自定义的类在没有重写Object中equals()方法的情况下&#xff0c;调用的就是Object类中声明的…...

【51单片机】第一个小程序 —— 点亮LED灯

学习使用的开发板&#xff1a;STC89C52RC/LE52RC 编程软件&#xff1a;Keil5 烧录软件&#xff1a;stc-isp 开发板实图&#xff1a; 文章目录 单片机介绍LED灯介绍练习创建第一个项目点亮LED灯LED周期闪烁 单片机介绍 单片机&#xff0c;英文Micro Controller Unit&#xff0…...

如何通过自动化有效地简化 Active Directory 操作?

我们都知道规模稍微大一点的企业为了便于计算机的管理&#xff0c;基本都上了微软的AD域控制器。 那么肯定就会存在这么一个问题&#xff0c; 不断的会有计算机加入或者是退出域控制器&#xff0c;批量的创建、修改、删除AD域用户&#xff0c;如果企业的架构需要改变&#xff…...

挑战杯推荐项目

“人工智能”创意赛 - 智能艺术创作助手&#xff1a;借助大模型技术&#xff0c;开发能根据用户输入的主题、风格等要求&#xff0c;生成绘画、音乐、文学作品等多种形式艺术创作灵感或初稿的应用&#xff0c;帮助艺术家和创意爱好者激发创意、提高创作效率。 ​ - 个性化梦境…...

Lombok 的 @Data 注解失效,未生成 getter/setter 方法引发的HTTP 406 错误

HTTP 状态码 406 (Not Acceptable) 和 500 (Internal Server Error) 是两类完全不同的错误&#xff0c;它们的含义、原因和解决方法都有显著区别。以下是详细对比&#xff1a; 1. HTTP 406 (Not Acceptable) 含义&#xff1a; 客户端请求的内容类型与服务器支持的内容类型不匹…...

Spring Boot 实现流式响应(兼容 2.7.x)

在实际开发中&#xff0c;我们可能会遇到一些流式数据处理的场景&#xff0c;比如接收来自上游接口的 Server-Sent Events&#xff08;SSE&#xff09; 或 流式 JSON 内容&#xff0c;并将其原样中转给前端页面或客户端。这种情况下&#xff0c;传统的 RestTemplate 缓存机制会…...

CocosCreator 之 JavaScript/TypeScript和Java的相互交互

引擎版本&#xff1a; 3.8.1 语言&#xff1a; JavaScript/TypeScript、C、Java 环境&#xff1a;Window 参考&#xff1a;Java原生反射机制 您好&#xff0c;我是鹤九日&#xff01; 回顾 在上篇文章中&#xff1a;CocosCreator Android项目接入UnityAds 广告SDK。 我们简单讲…...

现代密码学 | 椭圆曲线密码学—附py代码

Elliptic Curve Cryptography 椭圆曲线密码学&#xff08;ECC&#xff09;是一种基于有限域上椭圆曲线数学特性的公钥加密技术。其核心原理涉及椭圆曲线的代数性质、离散对数问题以及有限域上的运算。 椭圆曲线密码学是多种数字签名算法的基础&#xff0c;例如椭圆曲线数字签…...

html-<abbr> 缩写或首字母缩略词

定义与作用 <abbr> 标签用于表示缩写或首字母缩略词&#xff0c;它可以帮助用户更好地理解缩写的含义&#xff0c;尤其是对于那些不熟悉该缩写的用户。 title 属性的内容提供了缩写的详细说明。当用户将鼠标悬停在缩写上时&#xff0c;会显示一个提示框。 示例&#x…...

rnn判断string中第一次出现a的下标

# coding:utf8 import torch import torch.nn as nn import numpy as np import random import json""" 基于pytorch的网络编写 实现一个RNN网络完成多分类任务 判断字符 a 第一次出现在字符串中的位置 """class TorchModel(nn.Module):def __in…...

JAVA后端开发——多租户

数据隔离是多租户系统中的核心概念&#xff0c;确保一个租户&#xff08;在这个系统中可能是一个公司或一个独立的客户&#xff09;的数据对其他租户是不可见的。在 RuoYi 框架&#xff08;您当前项目所使用的基础框架&#xff09;中&#xff0c;这通常是通过在数据表中增加一个…...

保姆级教程:在无网络无显卡的Windows电脑的vscode本地部署deepseek

文章目录 1 前言2 部署流程2.1 准备工作2.2 Ollama2.2.1 使用有网络的电脑下载Ollama2.2.2 安装Ollama&#xff08;有网络的电脑&#xff09;2.2.3 安装Ollama&#xff08;无网络的电脑&#xff09;2.2.4 安装验证2.2.5 修改大模型安装位置2.2.6 下载Deepseek模型 2.3 将deepse…...

提升移动端网页调试效率:WebDebugX 与常见工具组合实践

在日常移动端开发中&#xff0c;网页调试始终是一个高频但又极具挑战的环节。尤其在面对 iOS 与 Android 的混合技术栈、各种设备差异化行为时&#xff0c;开发者迫切需要一套高效、可靠且跨平台的调试方案。过去&#xff0c;我们或多或少使用过 Chrome DevTools、Remote Debug…...