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

    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. nginx配置打印请求响应内容

    #放在http{}里面 log_format kyh ' [$time_local] "$request" $status \n' 'req_header:"$req_h ...

  2. go 命令

    go build go build,是我们非常常用的命令,它可以启动编译,把我们的包和相关的依赖编译成一个可执行的文件. go help build 帮助命令 go build go build . ...

  3. continue #结束本次循环进行下次循环

    #!/user/bin/python# -*- coding:utf-8 -*-print(111)while True: print(222) print(333) continue #结束本次循环 ...

  4. sklearn-数据预处理scale

    sklearn实战-乳腺癌细胞数据挖掘(博主亲自录制视频) https://study.163.com/course/introduction.htm?courseId=1005269003& ...

  5. gcc生成含有C信息的汇编

    title: gcc生成含有C信息的汇编 tags: gcc date: 2018-10-24 23:40:19 --- https://www.cnblogs.com/fengkang1008/p/ ...

  6. Elastic Stack之kibana使用

    Elastic Stack之kibana使用 作者:尹正杰  版权声明:原创作品,谢绝转载!否则将追究法律责任. 本篇博客数据流走向:FileBeat ===>Redis  ===>log ...

  7. 获取APP的元素信息和Activity

    一.获取元素信息 (1)第一种方法是,在windows命令行中输入uiautomatorviewer.bat(前提是已配置好Android SDK环境),按回车键:等待几秒后会打开UI Automat ...

  8. [C#]一个简易的、轻量级的方法并行执行线程辅助类

      一个简易的.轻量级的方法并行执行线程辅助类 在实际应用中,经常要让多个方法并行执行以节约运行时间,线程就是必不可少的了,而多线程的管理经常又是一件头疼的事情,比如方法并行执行异步的返回问题,方法并 ...

  9. 2016vijos 1-1 兔子的字符串(后缀数组 + 二分 + 哈希)

    题意: 给出一个字符串,至多将其划分为n部分,每一部分取出字典序最大的子串ci,最小化 最大的ci 先看一个简化版的问题: 给一个串s,再给一个s的子串t,问能否通过将串划分为k个部分,使t成为划分后 ...

  10. Structured Streaming Programming Guide结构化流编程指南

    目录 Overview Quick Example Programming Model Basic Concepts Handling Event-time and Late Data Fault T ...