From 5f07fba067dadcfed054320a394be4ccff73e569 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Sun, 12 Feb 2023 01:26:34 -0500 Subject: [PATCH] Core/GameObjects: Fixed crash with transport gameobjects that have only 1 entry in TransportAnimation/TransportRotation db2 Port From (https://github.com/TrinityCore/TrinityCore/commit/ea3f7f665b658744970a4cdc24b30e09342039cd) --- Source/Game/Entities/GameObject/GameObject.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Source/Game/Entities/GameObject/GameObject.cs b/Source/Game/Entities/GameObject/GameObject.cs index 8d2454a2b..8247c1651 100644 --- a/Source/Game/Entities/GameObject/GameObject.cs +++ b/Source/Game/Entities/GameObject/GameObject.cs @@ -4054,10 +4054,15 @@ namespace Game.Entities Vector3 prev = new(oldAnimation.Pos.X, oldAnimation.Pos.Y, oldAnimation.Pos.Z); Vector3 next = new(newAnimation.Pos.X, newAnimation.Pos.Y, newAnimation.Pos.Z); - float animProgress = (float)(newProgress - oldAnimation.TimeIndex) / (float)(newAnimation.TimeIndex - oldAnimation.TimeIndex); + Vector3 dst = next; + if (prev != next) + { + float animProgress = (float)(newProgress - oldAnimation.TimeIndex) / (float)(newAnimation.TimeIndex - oldAnimation.TimeIndex); - Vector3 dst = pathRotation.Multiply(Vector3.Lerp(prev, next, animProgress)); + dst = pathRotation.Multiply(Vector3.Lerp(prev, next, animProgress)); + } + dst = pathRotation.Multiply(dst); dst += _owner.GetStationaryPosition(); _owner.GetMap().GameObjectRelocation(_owner, dst.X, dst.Y, dst.Z, _owner.GetOrientation()); @@ -4070,9 +4075,14 @@ namespace Game.Entities Quaternion prev = new(oldRotation.Rot[0], oldRotation.Rot[1], oldRotation.Rot[2], oldRotation.Rot[3]); Quaternion next = new(newRotation.Rot[0], newRotation.Rot[1], newRotation.Rot[2], newRotation.Rot[3]); - float animProgress = (float)(newProgress - oldRotation.TimeIndex) / (float)(newRotation.TimeIndex - oldRotation.TimeIndex); + Quaternion rotation = next; - Quaternion rotation = Quaternion.Lerp(prev, next, animProgress); + if (prev != next) + { + float animProgress = (float)(newProgress - oldRotation.TimeIndex) / (float)(newRotation.TimeIndex - oldRotation.TimeIndex); + + rotation = Quaternion.Lerp(prev, next, animProgress); + } _owner.SetLocalRotation(rotation.X, rotation.Y, rotation.Z, rotation.W); _owner.UpdateModelPosition();