我想在一段时间内将 ObjectA 的旋转 SLERP 朝向 ObjectB 的位置。我正在工作的插值,我 can't 弄清楚的是如何产生 DestinationRotation(Look to Rotation,或旋转 ObjectA需要最终达到)
实现该目标的步骤是什么?
我有什么:
我如何计算 Look to Rotation?
注意:这是使用 Unreal Engine 空间数学库的 Verse 编程语言,但我的问题不在于代码,而在于知道以何种顺序使用哪些工具(数学)。
loop:
Sleep(0.0)
CurrentTime := GetSimulationElapsedTime()
DeltaTime := CurrentTime - PreviousTime
set PreviousTime = CurrentTime
var MoveToPosition : vector2 = vector2{X := 0.0, Y := 0.0}
# Player Current Position
if (Agent := agent[Player], FortChar := Agent.GetFortCharacter[], Trans := FortChar.GetTransform(), Position := Trans.Translation):
set MoveToPosition = vector2{X := Position.X, Y := Position.Y}
SpiderTrans := Spider.GetTransform()
SpiderVec := SpiderTrans.Translation
CurrentSpiderRotation := SpiderTrans.Rotation
CurrentSpiderPos := vector2{X := SpiderVec.X, Y := SpiderVec.Y}
DeltaSpeed := SpiderSpeed * DeltaTime
NewPos := Lerp(CurrentSpiderPos, MoveToPosition, DeltaSpeed)
FinalMoveVector := vector3{X := NewPos.X, Y := NewPos.Y, Z := SpiderVec.Z}
# This is where my rotation gets wonky
DP := DotProduct(CurrentSpiderPos, MoveToPosition)
var NewRotation : rotation = CurrentSpiderRotation.ApplyLocalRotationZ(DP)
if (set NewRotation = Slerp[CurrentSpiderRotation,NewRotation, SpiderSpeed]) {}
# Movement works fine, but rotation is all over the place
if (Spider.TeleportTo[FinalMoveVector, NewRotation]) {}