【UE4】 第05講 【MOBA製作日記】 發射物方向調整

(版權聲明,禁止轉載)

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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章