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

常用的网站类型有哪些类型有哪些类型短链接在线生成免费

常用的网站类型有哪些类型有哪些类型,短链接在线生成免费,东莞效果好的网站建设,wordpress 网上支付UE5 游戏模板 —— TopDownGame 俯视角游戏 前言一、模块导入二、TopDownGameMode三、TopDownPlayerController1、构造函数2、SetupInputComponent初始化新输入系统处理输入逻辑 四、TopDownCharacter五、射线检测总结 前言 上一篇文章介绍了一下PuzzleGame模板的流程&#xf…

UE5 游戏模板 —— TopDownGame 俯视角游戏

  • 前言
  • 一、模块导入
  • 二、TopDownGameMode
  • 三、TopDownPlayerController
    • 1、构造函数
    • 2、SetupInputComponent
      • 初始化新输入系统
      • 处理输入逻辑
  • 四、TopDownCharacter
  • 五、射线检测
  • 总结

前言

上一篇文章介绍了一下PuzzleGame模板的流程,我们循序渐进这次介绍TopDownGame。
实际上TopDownGame和之前的PuzzleGame非常类似都是俯视角都要使用射线检测去做相应的判定。但是TopDownGame提供了角色寻路和角色位移的方式。


一、模块导入

UE是以导入模块来构建项目的,我们可以自己定义插件等内容当作一个模块来进行导入。
可以看到下图中导入了很多的模块
在这里插入图片描述
其中 “Core”, “CoreUObject”, “Engine”, “InputCore” 是常用的也是默认都会导入的几个模块,有着最基础的内容。
“AIModule” 这个是用作寻路的必要模块
“Niagara” 粒子系统相关的模块
“EnhancedInput” 新的输入系统模块

二、TopDownGameMode

我们在之前的PuzzleGame中就有讲解过,下面的方式可以指定C++的蓝图派生类
在这里插入图片描述

三、TopDownPlayerController

1、构造函数

还是和上一节的内容相似,都是显示鼠标和设置鼠标的默认类型。
CachedDestination用于记录点击到的点
FollowTime用于记录鼠标按住的时间
在这里插入图片描述

2、SetupInputComponent

初始化新输入系统

在这里插入图片描述
获取新输入的本地玩家子系统,对子系统设置MappingContext

	// Add Input Mapping Contextif (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(GetLocalPlayer())){Subsystem->AddMappingContext(DefaultMappingContext, 0);}

将InputComponent 转换成新输入组件并绑定事件

// Set up action bindings
if (UEnhancedInputComponent* EnhancedInputComponent = Cast<UEnhancedInputComponent>(InputComponent))
{// Setup mouse input eventsEnhancedInputComponent->BindAction(SetDestinationClickAction, ETriggerEvent::Started, this, &ATestTopDownPlayerController::OnInputStarted);EnhancedInputComponent->BindAction(SetDestinationClickAction, ETriggerEvent::Triggered, this, &ATestTopDownPlayerController::OnSetDestinationTriggered);EnhancedInputComponent->BindAction(SetDestinationClickAction, ETriggerEvent::Completed, this, &ATestTopDownPlayerController::OnSetDestinationReleased);EnhancedInputComponent->BindAction(SetDestinationClickAction, ETriggerEvent::Canceled, this, &ATestTopDownPlayerController::OnSetDestinationReleased);// Setup touch input eventsEnhancedInputComponent->BindAction(SetDestinationTouchAction, ETriggerEvent::Started, this, &ATestTopDownPlayerController::OnInputStarted);EnhancedInputComponent->BindAction(SetDestinationTouchAction, ETriggerEvent::Triggered, this, &ATestTopDownPlayerController::OnTouchTriggered);EnhancedInputComponent->BindAction(SetDestinationTouchAction, ETriggerEvent::Completed, this, &ATestTopDownPlayerController::OnTouchReleased);EnhancedInputComponent->BindAction(SetDestinationTouchAction, ETriggerEvent::Canceled, this, &ATestTopDownPlayerController::OnTouchReleased);
}

处理输入逻辑

点击鼠标左键开始时先停止角色移动

void ATestTopDownPlayerController::OnInputStarted()
{StopMovement();
}

按住触发鼠标左键
1.先累加帧时间间隔
2.发射射线(可能会疑问这个发射射线的方法,其实是对之前PuzzleGame中发射射线方法的一个封装下面详细讲解一下这个地方)
3.记录射线碰撞的点
4.计算移动的方向向量

void ATestTopDownPlayerController::OnSetDestinationTriggered()
{// We flag that the input is being pressedFollowTime += GetWorld()->GetDeltaSeconds();// We look for the location in the world where the player has pressed the inputFHitResult Hit;bool bHitSuccessful = false;if (bIsTouch){bHitSuccessful = GetHitResultUnderFinger(ETouchIndex::Touch1, ECollisionChannel::ECC_Visibility, true, Hit);}else{bHitSuccessful = GetHitResultUnderCursor(ECollisionChannel::ECC_Visibility, true, Hit);}// If we hit a surface, cache the locationif (bHitSuccessful){CachedDestination = Hit.Location;}// Move towards mouse pointer or touchAPawn* ControlledPawn = GetPawn();if (ControlledPawn != nullptr){FVector WorldDirection = (CachedDestination - ControlledPawn->GetActorLocation()).GetSafeNormal();ControlledPawn->AddMovementInput(WorldDirection, 1.0, false);}
}

松开鼠标左键
如果按键按下的时长小于设定值判定是鼠标瞬间点击,将玩家使用导航移动到目标点,同时播放粒子特效和声音

void ATestTopDownPlayerController::OnSetDestinationReleased()
{// If it was a short pressif (FollowTime <= ShortPressThreshold){// We move there and spawn some particlesUAIBlueprintHelperLibrary::SimpleMoveToLocation(this, CachedDestination);UNiagaraFunctionLibrary::SpawnSystemAtLocation(this, FXCursor, CachedDestination, FRotator::ZeroRotator, FVector(1.f, 1.f, 1.f), true, true, ENCPoolMethod::None, true);if (AudioSound != nullptr){UGameplayStatics::PlaySoundAtLocation(GetWorld(), AudioSound, CachedDestination);}}FollowTime = 0.f;
}

四、TopDownCharacter

初始化相机和相机臂
在这里插入图片描述

五、射线检测

我们已经遇到了多次射线检测让我们来仔细看一下

首先无论是哪种射线检测函数本质上是从一个点到另一个点的连线在此连线的路径上是否有物体遮挡碰撞。
1.我们要先获取到鼠标在屏幕上面的坐标
2.将屏幕上的坐标转换为世界中的坐标,可以想象是摄像机的那个投影面的位置
3.需要知道方向,其实就是摄像机看向的方向
4.确定终点,起点+方向*长度
5.传递需要碰撞的参数,调用LineTraceSingleByChannel

在PuzzleGame中我们曾用过这个函数,获取到了世界的位置和方向,实际上就是获取屏幕鼠标位置让后通过矩阵转换得到最终的值
在这里插入图片描述
我们现在在来看一下TopDownGame的射线检测
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
其实本质的原理都是一样的


总结

以上就是今天要讲的内容,自此两个典型的俯视角游戏就介绍到这里,接下来是第一人称和第三人称射击游戏的模板。

http://www.dtcms.com/wzjs/447738.html

相关文章:

  • 厦门 网站建设常见的微信营销方式有哪些
  • 携程网网站规划建设特点网站优化排名服务
  • 贵阳网站改版电商运营工资大概多少
  • 投标文件网站开发技术部分中国站长站
  • 网站建设 租赁网站自动推广软件
  • 京山网站开发关键字c语言
  • 建立网站有什么作用电商平台推广方式有哪些
  • 教育培训网站制作培训体系包括四大体系
  • 烟台seo网站推广百度搜索资源平台官网
  • 泉州网站建设有哪些黄页大全
  • 删除wordpress文明seo技术教程网
  • 个人网站设计及实现论文软文标题大全
  • 做网站需要注册商标吗武汉seo网站推广培训
  • 企业网站用织梦好吗营业推广的目标通常是
  • 北京网站建设公司网站优化资讯百度安装
  • 网站建设ppt演示文档seo网站推广软件排名
  • 专业开发app公司seo优化网站优化
  • 网站被镜像怎么做合肥百度关键词优化
  • 金华网站建设方案优化网络营销有哪些
  • 可信网站注册河北百度seo
  • 寻找做项目的网站临沂seo代理商
  • 江苏多地发布最新情况湖南企业竞价优化首选
  • 网站开发赚钱么今日热搜榜前十名
  • 域名的网站建设方案书怎么写宁波seo
  • 做网站卖菜刀需要什么手续自己怎么做关键词优化
  • 武汉网站改版维护怎么把广告发到各大平台
  • 做中国旅游网站的目的与必要性东莞网络排名优化
  • 企业怎样做网站百度推广产品
  • 常州模板建站代理关键词搜索量查询工具
  • 网站策划 英文如何优化培训体系