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

    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. SpringBoot整合Freemarker+Mybatis

    开发工具 , 开始 新建工程 .选择Spring Initializr 下一步 下一步,选择需要的组件 ..改一下工程名,Finish ..目录结构 首先,修改pom文件 然后,将applicatio ...

  2. JS事件(三)部分常用事件

    1.滚动条事件scroll EventUtil.addHandler(window,"scroll",function(event){ if(document.compatMode ...

  3. Elastic 开发篇(3)

    1.报错: java.lang.NoSuchFieldError: FAIL_ON_SYMBOL_HASH_OVERFLOW 原因: 系统中已引入jackson版本,但版本较低,缺少所需要的字段. 解 ...

  4. tuple数组、文件操作

    halcon自带案例的学习. Tuple1 := [,,,,] //数组 Number := |Tuple1| //元素个数 SingleElement := Tuple1[] Part := Tup ...

  5. jquery的checked以及disabled

    下面只提到checked,其实disabled在jquery里的用法和checked是一模一样的 下边两种写法没有任何区别 只是少了些代码而已... ------------------------- ...

  6. String 类中的几个练习--获取指定字符串中,大写字母、小写字母、数字的个数||获取一个字符串中,另一个字符串出现的次数

    package cn.homework.demo1; public class GetCount { /* * 获取一个字符串中,另一个字符串出现的次数 * 思想: * 1. indexOf到字符串中 ...

  7. gulp API 文档

    gulp.src(globs[, options]) 输出(Emits)符合所提供的匹配模式(glob)或者匹配模式的数组(array of globs)的文件. 将返回一个 Vinyl files  ...

  8. go 学习资源和GitHub库

    go httprouter 源码包 https://github.com/julienschmidt/httprouter 用例 https://github.com/gsingharoy/httpr ...

  9. shiro的基本认识及做一个简单的授权登陆的例子

    先推荐一个网站,无意中发现的.感觉蛮好的. 推荐一套完整的Shiro Demo,免费的.Shiro Demo:http://www.sojson.com/shiroDemo已经部署到线上,地址是htt ...

  10. laravel 5.4 fopen(): Filename cannot be empty

    1.出错的报错信息(我在用laravel5.4文件上传时候出错的) laravel 5.4 fopen(): Filename cannot be empty 2.解决的方法 在php.ini中修改临 ...