UE5 C++ Gas开发 学习记录(一)

news2024/9/30 15:29:44

一个新坑,在TPS的空余时间学习

创建了自己,敌人的BaseCharacter和子类,创建了Gamemode,创建了Controller

AuraCharacterBase.h

// Fill out your copyright notice in the Description page of Project Settings. #pragma once #include "CoreMinimal.h" #include "GameFramework/Character.h" #include "AuraCharacterBase.generated.h" UCLASS(Abstract) class MYGAS_API AAuraCharacterBase : public ACharacter { GENERATED_BODY() public: // Sets default values for this character's properties AAuraCharacterBase(); protected: // Called when the game starts or when spawned virtual void BeginPlay() override; //TObjectPtr是一个模板类,用来指向UObject,并且在被销毁的时候自动设置为nullptr UPROPERTY(EditAnywhere,Category="Combat") TObjectPtr<USkeletalMeshComponent> Weapon; };

// Fill out your copyright notice in the Description page of Project Settings. #include "Character/AuraCharacterBase.h" #include "Components/SkeletalMeshComponent.h" // Sets default values AAuraCharacterBase::AAuraCharacterBase() { // Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = false; //创建Weapon Weapon = CreateDefaultSubobject<USkeletalMeshComponent>("Weapon"); //初始化所需的Attach Parent和SocketName,以便在组件注册时附加 Weapon->SetupAttachment(GetMesh(),FName("WeaponHandSocket")); //设置Weapon的碰撞为NoCollision Weapon->SetCollisionEnabled(ECollisionEnabled::NoCollision); } // Called when the game starts or when spawned void AAuraCharacterBase::BeginPlay() { Super::BeginPlay(); }

AuraCharacter.h

// Fill out your copyright notice in the Description page of Project Settings. #pragma once #include "CoreMinimal.h" #include "Camera/CameraComponent.h" #include "Character/AuraCharacterBase.h" #include "GameFramework/SpringArmComponent.h" #include "AuraCharacter.generated.h" /** * */ UCLASS() class MYGAS_API AAuraCharacter : public AAuraCharacterBase { AAuraCharacter(); GENERATED_BODY() UPROPERTY(EditAnywhere,Category="My") UCameraComponent* FollowCamera; UPROPERTY(EditAnywhere,Category="My") USpringArmComponent* CameraBoom; public: /** Returns CameraBoom subobject **/ FORCEINLINE class USpringArmComponent* GetCameraBoom() const { return CameraBoom; } /** Returns FollowCamera subobject **/ FORCEINLINE class UCameraComponent* GetFollowCamera() const { return FollowCamera; } };

// Fill out your copyright notice in the Description page of Project Settings. #include "Character/AuraCharacter.h" #include "GameFramework/CharacterMovementComponent.h" AAuraCharacter::AAuraCharacter() { //初始化弹簧臂,并且绑定在Root上 CameraBoom = CreateDefaultSubobject<USpringArmComponent>("CameraBoom"); CameraBoom ->SetupAttachment(RootComponent); CameraBoom->TargetArmLength = 400.f; CameraBoom->bUsePawnControlRotation = true; //初始化相机,并且安装到弹簧臂上 FollowCamera = CreateDefaultSubobject<UCameraComponent>("FollowCamera"); FollowCamera->SetupAttachment(CameraBoom,USpringArmComponent::SocketName); FollowCamera->bUsePawnControlRotation = false; //初始化角色移动 //控制角色是否朝着速度的方向进行旋转 GetCharacterMovement()->bOrientRotationToMovement= true; //控制旋转的速度 GetCharacterMovement()->RotationRate = FRotator(0.f,400.f,0.f); //控制移动是否在平面上 GetCharacterMovement()->bConstrainToPlane = true; //当在平面为true的时候,是否强制与平面对齐 GetCharacterMovement()->bSnapToPlaneAtStart = true; bUseControllerRotationPitch = false; bUseControllerRotationRoll = false; bUseControllerRotationYaw = false; }

AuraEnemy.h

// Fill out your copyright notice in the Description page of Project Settings. #pragma once #include "CoreMinimal.h" #include "Character/AuraCharacterBase.h" #include "Interaction/EnemyInterface.h" #include "AuraEnemy.generated.h" /** * */ UCLASS() class MYGAS_API AAuraEnemy : public AAuraCharacterBase , public IEnemyInterface { GENERATED_BODY() public: virtual void HighlightActor() override; virtual void UnHighlightActor() override; };

// Fill out your copyright notice in the Description page of Project Settings. #include "Character/AuraEnemy.h" void AAuraEnemy::HighlightActor() { } void AAuraEnemy::UnHighlightActor() { }

EnemyInterface接口

// Fill out your copyright notice in the Description page of Project Settings. #pragma once #include "CoreMinimal.h" #include "UObject/Interface.h" #include "EnemyInterface.generated.h" // This class does not need to be modified. UINTERFACE(MinimalAPI) class UEnemyInterface : public UInterface { GENERATED_BODY() }; /** * */ class MYGAS_API IEnemyInterface { GENERATED_BODY() // Add interface functions to this class. This is the class that will be inherited to implement this interface. public: virtual void HighlightActor() = 0; virtual void UnHighlightActor() = 0; };

AuraPlayerController.h

// Fill out your copyright notice in the Description page of Project Settings. #pragma once #include "CoreMinimal.h" #include "../../../../../../../../Program Files/Epic Games/UE_5.1/Engine/Plugins/EnhancedInput/Source/EnhancedInput/Public/InputMappingContext.h" #include "GameFramework/PlayerController.h" #include "AuraPlayerController.generated.h" //声明一个UInputMappingContext类.然后在下面直接调用这个类 class UInputMappingContext; class UInputAction; struct FInputActionValue; /** * */ UCLASS() class MYGAS_API AAuraPlayerController : public APlayerController { GENERATED_BODY() public: AAuraPlayerController(); protected: virtual void BeginPlay() override; virtual void SetupInputComponent() override; private: UPROPERTY(EditAnywhere,Category="Input") TObjectPtr<UInputMappingContext> AuraContext; UPROPERTY(EditAnywhere,Category="Input") TObjectPtr<UInputAction> MoveAction; void Move(const struct FInputActionValue& InputActionValue); };

// Fill out your copyright notice in the Description page of Project Settings. #include "PlayerController/AuraPlayerController.h" #include "../../../../../../../../Program Files/Epic Games/UE_5.1/Engine/Plugins/EnhancedInput/Source/EnhancedInput/Public/EnhancedInputComponent.h" #include "../../../../../../../../Program Files/Epic Games/UE_5.1/Engine/Plugins/EnhancedInput/Source/EnhancedInput/Public/EnhancedInputSubsystems.h" #include "Engine/LocalPlayer.h" #include "GameFramework/Pawn.h" AAuraPlayerController::AAuraPlayerController() { bReplicates = true; } void AAuraPlayerController::BeginPlay() { Super::BeginPlay(); //检查AuraContext是否有效 check(AuraContext); UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(GetLocalPlayer()); check(Subsystem); //Add a control mapping context. 第一个参数AuraContext是映射集合,第二个参数是映射的优先级 Subsystem->AddMappingContext(AuraContext,0); //设置鼠标光标行为和输入模式 //是否显示鼠标 bShowMouseCursor=true; //光标默认样式 DefaultMouseCursor = EMouseCursor::Default; //设置游戏和UI的输入模式 FInputModeGameAndUI InputModeData; //鼠标可以移动到视口外 InputModeData.SetLockMouseToViewportBehavior(EMouseLockMode::DoNotLock); //不隐藏鼠标 InputModeData.SetHideCursorDuringCapture(false); SetInputMode(InputModeData); } void AAuraPlayerController::SetupInputComponent() { Super::SetupInputComponent(); UEnhancedInputComponent* EnhancedInputComponent = CastChecked<UEnhancedInputComponent>(InputComponent); //在启动的时候绑定MoveAction组件,并且把输入的参数传递给Move函数 EnhancedInputComponent->BindAction(MoveAction,ETriggerEvent::Triggered,this,&AAuraPlayerController::Move); } void AAuraPlayerController::Move(const FInputActionValue& InputActionValue) { // const FVector2d InputAxisVector = InputActionValue.Get<FVector2D>(); const FRotator Rotation = GetControlRotation(); const FRotator YawRotation(0.f,Rotation.Yaw,0.f); const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X); const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y); // if(APawn* ControlledPawn = GetPawn<APawn>()) { ControlledPawn->AddMovementInput(ForwardDirection,InputAxisVector.Y); ControlledPawn->AddMovementInput(RightDirection,InputAxisVector.X); } }

AuraGameModeBase.h

// Fill out your copyright notice in the Description page of Project Settings. #pragma once #include "CoreMinimal.h" #include "GameFramework/GameModeBase.h" #include "AuraGameModeBase.generated.h" /** * */ UCLASS() class MYGAS_API AAuraGameModeBase : public AGameModeBase { GENERATED_BODY() };

创建角色,继承自Character

怪物也同理,但是新制作了怪物的动画蓝图模板

怪物的动画蓝图继承自怪物模板

制作了输入

制作了PlayController

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

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

相关文章

H264/H265基本编码参数1

本文主要讲解一些视频编码相关的基本概念 像素 像素是图像的基本单元&#xff0c;一个个像素就组成了图像。你可以认为像素就是图像中的一个点。我们来直观地看看像素是怎么组成图像的。在下面这张图中&#xff0c;你可以看到一个个方块&#xff0c;这些方块就是像素。 分辨…

【GameFramework框架内置模块】4、内置模块之调试器(Debugger)

推荐阅读 CSDN主页GitHub开源地址Unity3D插件分享简书地址QQ群&#xff1a;398291828 大家好&#xff0c;我是佛系工程师☆恬静的小魔龙☆&#xff0c;不定时更新Unity开发技巧&#xff0c;觉得有用记得一键三连哦。 一、前言 【GameFramework框架】系列教程目录&#xff1a;…

开启数字内容创作的新时代

目录 技术解析 未来展望 技术解析 Sora是一款由OpenAI开发的先进AI视频模型&#xff0c;其技术架构基于深度学习和自然语言处理技术。该模型的核心算法原理包括使用深度神经网络进行视频内容的理解、生成和互动。 在技术架构方面&#xff0c;Sora采用了一种混合的神经网络结…

五种多目标优化算法(NSWOA、MOJS、MOAHA、MOPSO、NSGA2)性能对比(提供MATLAB代码)

一、5种多目标优化算法简介 1.1NSWOA 1.2MOJS 1.3MOAHA 1.4MOPSO 1.5NSGA2 二、5种多目标优化算法性能对比 为了测试5种算法的性能将其求解9个多目标测试函数&#xff08;zdt1、zdt2 、zdt3、 zdt4、 zdt6 、Schaffer、 Kursawe 、Viennet2、 Viennet3&#xff09;&#xff0…

15:00面试,15:06就出来了,问的问题过于变态了。。。

我从一家小公司转投到另一家公司&#xff0c;期待着新的工作环境和机会。然而&#xff0c;新公司的加班文化让我有些始料未及。虽然薪资相对较高&#xff0c;但长时间的工作和缺乏休息使我身心俱疲。 就在我逐渐适应这种高强度的工作节奏时&#xff0c;公司突然宣布了一则令人…

EXCEL如何从另一个表查找匹配信息

目录 1.背景&#xff1a;我们有一个目标呈现表&#xff0c;想要从另一个表中查询得到信息&#xff0c;比如根据身份证id查询该id的名字、性别等个人基本信息&#xff0c;或者从另一个财务信息表查询该id的工资信息等&#xff1b; 2.基础方法&#xff1a;利用VLOOKUP函数根据单…

NGINX服务器配置实现加密的WebSocket连接WSS协议

一、背景 最近在做小程序开发&#xff0c;需要在nginx中配置websocket加密模式&#xff0c;即wss。初次配置wss时&#xff0c;踩了两个小时的坑&#xff0c;本文将踩坑过程分享给大家&#xff0c;有需要用到的伙伴可以直接copy即可实现&#xff0c;节省宝贵时间。 二、WebSo…

VS2022调试技巧(一)

什么是bug&#xff1f; 在1945年&#xff0c;美国科学家Grace Hopper在进行计算机编程时&#xff0c;发现一只小虫子钻进了一个真空管&#xff0c;导致计算机无法正常工作。她取出虫子后&#xff0c;计算机恢复了正常&#xff0c;由此&#xff0c;她首次将“Bug”这个词用来描…

用html编写的小广告板

用html编写的小广告板 相关代码 <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><title>Document</tit…

刘知远LLM——Transformer与预训练模型

文章目录 注意力机制原理介绍注意力机制的各种变式注意力机制的特点 Transformer结构概述Transformer整体结构 输入层byte pair encodingpositional encoding Transformer BlockEncoder BlockMulti-Head Attention Decoder Block其他tricks总结 预训练语言模型语言建模概述预训…

二叉搜索树题目:二叉搜索树中的众数

文章目录 题目标题和出处难度题目描述要求示例数据范围进阶 解法一思路和算法代码复杂度分析 解法二思路和算法代码复杂度分析 解法三思路和算法代码复杂度分析 题目 标题和出处 标题&#xff1a;二叉搜索树中的众数 出处&#xff1a;501. 二叉搜索树中的众数 难度 3 级 …

峰值检测电路

常用的峰值检测电路&#xff0c;如下图所示。 该电路有两种工作状态&#xff1a; 1、充电状态&#xff1a;D2导通&#xff0c;D1截止。 当U1的端比-端大时&#xff0c;V1VIN&#xff0c;VCV1-VD2&#xff0c;VOUTVC。这时&#xff0c;给电容C1充电。由于D1截止没有环路&#…

Shell脚本介绍及脚本功能

文章目录 一、什么是shell二、hello word2.1 echo2.2第一个脚本 三、Bash的基本功能3.1别名3.2常用快捷键3.3输入输出3.4 输出重定向3.5 多命令执行3.6 管道符3.7 通配符和特殊符号 一、什么是shell Shell 是一个用 C 语言编写的程序&#xff0c;它是用户使用 Linux 的桥梁。S…

背包问题(介绍+例题+代码+注解)

目录 介绍&#xff1a; 一、01背包 题目描述 输入描述: 输出描述: 代码&#xff1a; 二、完全背包 题目描述 输入描述: 输出描述: 代码&#xff1a; 三、多重背包 题目描述 输入描述: 输出描述: 代码&#xff1a; 四、背包问题 题目描述 输入描述: 输出描…

Mybatis2

Mybatis2 本章目标&#xff1a; myBatis类型别名处理 myBatis参数处理 myBatis结果集类型 myBatis结果集列名和属性名称对应方式处理 附录 本章内容 一、类型别名&#xff08;typeAliases&#xff09;处理 类型别名可为 Java 类型设置一个缩写名字。 它仅用于 XML 配置…

使用EFCore连接SQLite

简介 在使用EFCore连接SQLite之前我们先来了解一下SQLite SQLite是一个轻量级、自包含、无服务器、零配置的事务性SQL数据库引擎&#xff0c;它支持SQL92标准的大多数查询语言并兼容ACID事务。具体如下&#xff1a; 轻量级&#xff1a;SQLite非常轻巧&#xff0c;它的库体积…

[算法沉淀记录] 排序算法 —— 堆排序

排序算法 —— 堆排序 算法基础介绍 堆排序&#xff08;Heap Sort&#xff09;是一种基于比较的排序算法&#xff0c;它利用堆这种数据结构来实现排序。堆是一种特殊的完全二叉树&#xff0c;其中每个节点的值都必须大于或等于&#xff08;最大堆&#xff09;或小于或等于&am…

Huggingface学习笔记

课程地址&#xff1a;【HuggingFace简明教程,BERT中文模型实战示例.NLP预训练模型,Transformers类库,datasets类库快速入门.】 什么是huggingface&#xff1f; huggingface是一个开源社区&#xff0c;提供了先进的NLP模型、数据集以及工具。 主要模型&#xff1a; 安装环境&…

Rust升级慢,使用国内镜像进行加速

背景 rustup 是 Rust 官方的跨平台 Rust 安装工具&#xff0c;国内用户使用rustup update的时候&#xff0c;网速非常慢&#xff0c;可以使用国内的阿里云镜像源来进行加速 0x01 配置方法 1. Linux与Mac OS用户配置环境变量 修改~/.bash_profile文件添加如下内容&#xff1…

Docker基础篇(六) dockerfile体系结构语法

FROM&#xff1a;基础镜像&#xff0c;当前新镜像是基于哪个镜像的 MAINTAINER &#xff1a;镜像维护者的姓名和邮箱地址 RUN&#xff1a;容器构建时需要运行的命令 EXPOSE &#xff1a;当前容器对外暴露出的端口号 WORKDIR&#xff1a;指定在创建容器后&#xff0c;终端默认登…