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

    UPROPERTY(VisibleAnywhere,Category="Components")
UStaticMeshComponent* MeshComp; UPROPERTY(VisibleAnywhere, Category = "Components")
UBoxComponent* OverlapComp;

导入头文件

#include "Components/BoxComponent.h"
#include "Components/StaticMeshComponent.h"
#include "Components/ArrowComponent.h"
#include "GameFramework/Character.h"
#include "Kismet/GameplayStatics.h"

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

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

定义弹射力度和弹射角度

    UPROPERTY(EditInstanceOnly, Category = "LaunchPad")
float LaunchStrength; UPROPERTY(EditInstanceOnly, Category = "LaunchPad")
float LaunchPitchAngle;

定义一个粒子系统

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

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

    OverlapComp = CreateDefaultSubobject<UBoxComponent>(TEXT("OverlapComp"));
OverlapComp->SetBoxExtent(FVector(, , ));
RootComponent = OverlapComp; MeshComp = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MeshComp"));
MeshComp->SetupAttachment(RootComponent);

将OverlapLaunchPad函数和OverlapComp绑定在一起

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

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

    LaunchStrength = ;
LaunchPitchAngle = 35.0f;

实现OverlapLaunchPad函数

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

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. lucene之中文分词及其高亮显示(五)

    中文分词:即换个分词器 Analyzer analyzer = new StandardAnalyzer();// 标准分词器     换成  SmartChineseAnalyzer analyze ...

  2. 为SNP增加种族人群频率

    一.Ensemble:http://www.ensembl.info/2015/06/18/1000-genomes-phase-3-frequencies-genotypes-and-ld-data ...

  3. 面向对象【day08】:异常处理-断言(七)

    本节内容 1.概述 2.知识点回顾 3.断言 一.概述 python中断言,这个我是第一次听说到的,断言有什么用呢?断言就是做一些程序的检查工作,就是在执行之前需要做的一些检查,比如类似于安检一样,合 ...

  4. python--编写用例脚本

    from appium import webdriverimport time desired_caps = {}desired_caps['platformName'] = 'Android'des ...

  5. Linux记录-安装LAMP和R环境

    2.2 Apache httpd2.2.1 执行命令进行安装:yum install -y httpd2.2.2 开启服务:service httpd start2.2.3 设置开机自启动:chkco ...

  6. EF部分字段更新,忽略为null字段

    一般的更新代码是这样的 public T Update<T>(T entity) where T : ModelBase { var set = this.Set<T>(); ...

  7. canvas.drawImage()方法详解

    首先看html5.js /**@param {Element} img_elem@param {Number} dx_or_sx@param {Number} dy_or_sy@param {Numb ...

  8. 全面理解JavaScript中的 this

    全面理解JavaScript中的 this 上下文 VS 作用域 作用域(scope) 是在运行时代码中的某些特定部分中变量,函数和对象的可访问性.换句话 说,作用域决定了代码区块中变量和其他资源的可 ...

  9. Github 开源项目(二)gorun (go语言工具)

    gorun是一个工具,可以在Go程序的源代码中放置“爆炸线”来运行它,或者明确运行这样的源代码文件. 它的创建旨在试图让Go更加吸引那些习惯于Python和类似语言的人们,他们使用源代码进行最明显的操 ...

  10. vue使用vue-awesome-swiper及一些问题

    vue-awesome-swiper是基于swiper的一个轮播图插件,使用非常方便. 首先安装下 npm install vue-awesome-swiper --save 然后在入口文件main. ...