UE4中抛体物理模拟UProjectileMovementComponent
创始人
2024-03-20 03:03:50
0

UE4中抛体物理模拟UProjectileMovementComponent

  • 1.简述
  • 2.使用方法
  • 3.绘制抛物曲线
  • 4.绘制抛物曲线

1.简述

背景:实现抛体运动,反弹效果,抛物曲线等功能
通用实现可以使用spline绘制,物体按照下图接口可以根据时间更新位置

USplineComponent:GetLocationAtTime(Time, CoordinateSpace, bUseConstantVelocity)

为处理碰撞反弹等,本文考虑使用UProjectileMovementComponent相关 纯工具类组件 继承自UMovementComponent
UE4官方文档:
UProjectileMovementComponent

ProjectileMovementComponent会在tick期间更新另一个组件的位置,如果更新的Component开启了模拟物理,那么只有初始速度initial velocity非0时才会影响发射,物理模拟将会在这里接管。

2.使用方法

在BP中添加组件ProjectileMovement
在这里插入图片描述

在BP里设置默认参数,可以设置抛体的初始速度、最大速度、模拟反弹、每帧更新旋转、匹配速度方向、重力影响、加速度量级等
在这里插入图片描述
或者在BP侧 spawn时设置
在这里插入图片描述
或在构造函数中设置UProjectileMovementComponent组件的相关属性:

if(!ProjectileMovementComponent)
{// Use this component to drive this projectile's movement.ProjectileMovementComponent = CreateDefaultSubobject(TEXT("ProjectileMovementComponent"));ProjectileMovementComponent->SetUpdatedComponent(CollisionComponent);ProjectileMovementComponent->InitialSpeed = 3000.0f;ProjectileMovementComponent->MaxSpeed = 3000.0f;ProjectileMovementComponent->bRotationFollowsVelocity = true;ProjectileMovementComponent->bShouldBounce = true;ProjectileMovementComponent->Bounciness = 0.3f;ProjectileMovementComponent->ProjectileGravityScale = 0.0f;
}

3.绘制抛物曲线

匀变速运动的位移公式:S = Vt +0.5a * t^2,对应实现每帧运动的距离MoveDelta

FVector UProjectileMovementComponent::ComputeMoveDelta(const FVector& InVelocity, float DeltaTime) const
{const FVector NewVelocity = ComputeVelocity(InVelocity, DeltaTime);const FVector Delta = (InVelocity * DeltaTime) + (NewVelocity - InVelocity) * (0.5f * DeltaTime);return Delta;
}

4.绘制抛物曲线

可以根据上文原理绘制抛物曲线参考下图
在这里插入图片描述

相关内容

热门资讯

AWSECS:访问外部网络时出... 如果您在AWS ECS中部署了应用程序,并且该应用程序需要访问外部网络,但是无法正常访问,可能是因为...
银河麒麟V10SP1高级服务器... 银河麒麟高级服务器操作系统简介: 银河麒麟高级服务器操作系统V10是针对企业级关键业务...
AWSElasticBeans... 在Dockerfile中手动配置nginx反向代理。例如,在Dockerfile中添加以下代码:FR...
【NI Multisim 14...   目录 序言 一、工具栏 🍊1.“标准”工具栏 🍊 2.视图工具...
不能访问光猫的的管理页面 光猫是现代家庭宽带网络的重要组成部分,它可以提供高速稳定的网络连接。但是,有时候我们会遇到不能访问光...
​ToDesk 远程工具安装及... 目录 前言 ToDesk 优势 ToDesk 下载安装 ToDesk 功能展示 文件传输 设备链接 ...
北信源内网安全管理卸载 北信源内网安全管理是一款网络安全管理软件,主要用于保护内网安全。在日常使用过程中,卸载该软件是一种常...
AWS管理控制台菜单和权限 要在AWS管理控制台中创建菜单和权限,您可以使用AWS Identity and Access Ma...
AWR报告解读 WORKLOAD REPOSITORY PDB report (PDB snapshots) AW...
群晖外网访问终极解决方法:IP... 写在前面的话 受够了群晖的quickconnet的小水管了,急需一个新的解决方法&#x...