在头文件中定义网格体组件和重叠组件

  1. UPROPERTY(VisibleAnywhere,Category="Components")
  2. UStaticMeshComponent* MeshComp;
  3.  
  4. UPROPERTY(VisibleAnywhere, Category = "Components")
  5. UBoxComponent* OverlapComp;

导入头文件

  1. #include "Components/BoxComponent.h"
  2. #include "Components/StaticMeshComponent.h"
  3. #include "Components/ArrowComponent.h"
  4. #include "GameFramework/Character.h"
  5. #include "Kismet/GameplayStatics.h"

创建OverlapLaunchPad函数,重叠时发生弹射角色

  1. UFUNCTION()
  2. void OverlapLaunchPad(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);

定义弹射力度和弹射角度

  1. UPROPERTY(EditInstanceOnly, Category = "LaunchPad")
  2. float LaunchStrength;
  3.  
  4. UPROPERTY(EditInstanceOnly, Category = "LaunchPad")
  5. float LaunchPitchAngle;

定义一个粒子系统

  1. UPROPERTY(EditDefaultsOnly, Category = "LaunchPad")
  2. UParticleSystem* ActivateLaunchPadEffect;

设置重叠组件及其尺寸,设置网格体组件作为基底

  1. OverlapComp = CreateDefaultSubobject<UBoxComponent>(TEXT("OverlapComp"));
  2. OverlapComp->SetBoxExtent(FVector(, , ));
  3. RootComponent = OverlapComp;
  4.  
  5. MeshComp = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MeshComp"));
  6. MeshComp->SetupAttachment(RootComponent);

将OverlapLaunchPad函数和OverlapComp绑定在一起

  1. OverlapComp->OnComponentBeginOverlap.AddDynamic(this, &AFPSLaunchPad::OverlapLaunchPad);

初始化弹射力度和弹射角度

  1. LaunchStrength = ;
  2. LaunchPitchAngle = 35.0f;

实现OverlapLaunchPad函数

  1. void AFPSLaunchPad::OverlapLaunchPad(UPrimitiveComponent * OverlappedComponent, AActor * OtherActor, UPrimitiveComponent * OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
  2. {
  3. FRotator LaunchDirection = GetActorRotation();//获取Actor旋转度
  4. LaunchDirection.Pitch += LaunchPitchAngle;//俯仰角,可以让Actor不直接按旋转量旋转,而是朝着某一角度进行旋转
  5. FVector LaunchVelocity = LaunchDirection.Vector() * LaunchStrength;//弹射速率,将旋转量变为矢量再乘以弹射力度
  6.  
  7. ACharacter* OtherCharacter = Cast<ACharacter>(OtherActor);//强制转换为Character
  8. if (OtherCharacter)
  9. {
  10. OtherCharacter->LaunchCharacter(LaunchVelocity, true, true);//调用游戏内置的发射函数,后面两个参数可用于重写当前速率,无论从哪个方向走入发射平台都能确保弹射速率的一致性
  11.  
  12. UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), ActivateLaunchPadEffect, GetActorLocation());//原地创建发射器
  13. }
  14. else if (OtherComp && OtherComp->IsSimulatingPhysics())//检测角色是否转换失败
  15. {
  16. OtherComp->AddImpulse(LaunchVelocity, NAME_None, true);//施加相同速率的推力
  17.  
  18. UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), ActivateLaunchPadEffect, GetActorLocation());
  19. }
  20. }

Challenge Create a Launch Pad的更多相关文章

  1. Create Fiori List App Report with ABAP CDS view – PART 2

    In the Part 1 blog, we have discussed below topics CDS annotations for Fiori List Report. How to cre ...

  2. ios Programming:The Big Nerd Ranch Guid(6th Edition) (Joe Conway & AARON HILLEGASS 著)

    Introduction (已看) Prerequisites What Has Changed in the Sixth Edition? Our Teaching Philosophy How t ...

  3. Using Let’s Encrypt for free SSL Certs with Netscaler

    Using Let’s Encrypt for free SSL Certs with Netscaler If you haven’t heard, Let’s Encrypt (https://l ...

  4. 2015年最佳的12个 CSS 开发工具推荐

    CSS所能做的就是改变网页的布局.排版和调整字间距等,但编写 CSS 并不是一项容易的任务,当你接触新的 CSS3 属性及其各自的浏览器前缀的时候,你会发现很伤脑经.值得庆幸的是一些优秀的开发人员提供 ...

  5. Serial Port Programming using Win32 API(转载)

    In this tutorial we will learn How to communicate with an external device like a microcontroller boa ...

  6. Gazebo機器人仿真學習探索筆記(七)连接ROS

    中文稍后补充,先上官方原版教程.ROS Kinetic 搭配 Gazebo 7 附件----官方教程 Tutorial: ROS integration overview As of Gazebo 1 ...

  7. ROS_Kinetic_x 目前已更新的常用機器人資料 rosbridge agvs pioneer_teleop nao TurtleBot

    Running Rosbridge Description: This tutorial shows you how to launch a rosbridge server and talk to ...

  8. Making my own Autonomous Robot in ROS / Gazebo, Day 2: Enable the robot

    Day 2: Enable the robot Git Setting git checkout master git branch day2_enable_robot git push --set- ...

  9. 2.4G无线射频通信模块nRF24L01+开发笔记(基于MSP430RF6989与STM32f0308)(1.(2)有错误,详见更正)

    根据网上的nRF24L01+例程和TI提供的MSP430RF6989的硬件SPI总线例程编写程序,对硬件MSP-EXP430RF6989 Launch Pad+nRF24L01P射频模块(淘宝购买)进 ...

随机推荐

  1. Contest1593 - 2018-2019赛季多校联合新生训练赛第三场(部分题解)

    H 10255 自然数无序拆分 H 传送门 题干: 题目描述 美羊羊给喜羊羊和沸羊羊出了一道难题,说谁能先做出来,我就奖励给他我自己做的一样礼物.沸羊羊这下可乐了,于是马上答应立刻做出来,喜羊羊见状, ...

  2. JS with

    <script type="text/javascript"> function Dog(){ this.type="dog"; this.tail ...

  3. python字节(bytes)

    在 3.x 中,字符串和二进制数据完全区分开.文本总是 Unicode,由 str 类型表示,二进制数据则由 bytes 类型表示.Python 3 不会以任意隐式的方式混用 str 和 bytes, ...

  4. str

    print('字符串操作') s='abc DEF hij' print('首字母大写') print(s.capitalize()) print('全大写') print(s.upper()) pr ...

  5. 编写Excel文件的Golang库

    github:https://github.com/360EntSecGroup-Skylar/excelize 使用用例 https://dev.to/xuri/go-library-for-rea ...

  6. Event Recommendation Engine Challenge分步解析第五步

    一.请知晓 本文是基于: Event Recommendation Engine Challenge分步解析第一步 Event Recommendation Engine Challenge分步解析第 ...

  7. ActiveMQ详细入门使用教程

    ActiveMQ介绍 MQ是消息中间件,是一种在分布式系统中应用程序借以传递消息的媒介,常用的有ActiveMQ,RabbitMQ,kafka.ActiveMQ是Apache下的开源项目,完全支持JM ...

  8. angular,vue,react的基本语法—插值表达式,渲染数据,响应式数据

    基本语法: 1.插值表达式: vue:{{}} react:{} angular:{{}} 2.渲染数据 vue js: export default{ data(){ return{ msg:&qu ...

  9. Maccms8.x 命令执行漏洞分析

    下载链接https://share.weiyun.com/23802397ed25681ad45c112bf34cc6db 首先打开Index.php $m = be('get','m'); m参数获 ...

  10. Golang入门教程(六)关键字和数据类型

    在 Go 编程语言中,数据类型用于声明函数和变量. 数据类型的出现是为了把数据分成所需内存大小不同的数据,编程的时候需要用大数据的时候才需要申请大内存,就可以充分利用内存. 一.25个关键字 二.18 ...