角色發動技能的時候,需要預定義默認發射方向,如果發現方向不是自己預期的,就需要去做調整,需要用到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();