【UE4】 第05讲 发射物方向调整

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Nanhu2012/article/details/53158252

(版权声明,禁止转载)

       角色发动技能的时候,需要预定义默认发射方向,如果发现方向不是自己预期的,就需要去做调整,需要用到FTransform,FRotator,FQuat,实际上就是矩阵和四元数的计算问题了。

                              
 

                       默认获得右手骨骼坐标系的X轴作为发射方向,红色的那个轴,但是这个方向不合理

                              

        对X轴进行方向调整,变换流程是 左手骨骼局部坐标系->世界坐标系->绕Z轴旋转-70->绕Y轴旋转-10 即得到合理的方向

// 获取指定bone的transform
const int32 RHandIndex = GetMesh()->GetBoneIndex(TEXT("Bip01-R-Hand"));
const FTransform RHandTransform = GetMesh()->GetBoneTransform(RHandIndex);

// 设置发射物的初始轨道。
FVector LaunchDirection ;
FRotator RotOffsetZ(0.f,-70.f,0.f);
FRotator RotOffsetY(-10.f,0.f,0.f);
FQuat Rotator = RHandTransform.GetRotation();
Rotator = Rotator*RotOffsetZ.Quaternion()*RotOffsetY.Quaternion();

LaunchDirection = Rotator.GetAxisX();	

猜你喜欢

转载自blog.csdn.net/Nanhu2012/article/details/53158252