From aa16f36eac1ba1fc846ccb6cccf098381c0213b6 Mon Sep 17 00:00:00 2001 From: Damian Date: Fri, 19 Sep 2025 16:06:15 +0200 Subject: [PATCH] Lawnmower Chase Work Gardener chases but gets flipped --- Assets/Scenes/Levels/Quarry.unity | 20 ++++++----- .../Animation/GardenerChaseBehavior.cs | 34 ++----------------- 2 files changed, 14 insertions(+), 40 deletions(-) diff --git a/Assets/Scenes/Levels/Quarry.unity b/Assets/Scenes/Levels/Quarry.unity index 48e459da..5b052e5d 100644 --- a/Assets/Scenes/Levels/Quarry.unity +++ b/Assets/Scenes/Levels/Quarry.unity @@ -443520,15 +443520,15 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 6004009293778554413, guid: 1fda7fccaa5fbd04695f4c98d29bcbe0, type: 3} propertyPath: m_LocalScale.x - value: 3.68 + value: 1.5 objectReference: {fileID: 0} - target: {fileID: 6004009293778554413, guid: 1fda7fccaa5fbd04695f4c98d29bcbe0, type: 3} propertyPath: m_LocalScale.y - value: 2 + value: 1.5 objectReference: {fileID: 0} - target: {fileID: 6004009293778554413, guid: 1fda7fccaa5fbd04695f4c98d29bcbe0, type: 3} propertyPath: m_LocalScale.z - value: 2 + value: 1.5 objectReference: {fileID: 0} - target: {fileID: 6004009293778554413, guid: 1fda7fccaa5fbd04695f4c98d29bcbe0, type: 3} propertyPath: m_LocalPosition.x @@ -443540,19 +443540,23 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 6004009293778554413, guid: 1fda7fccaa5fbd04695f4c98d29bcbe0, type: 3} propertyPath: m_LocalRotation.w - value: 0.83432513 + value: 0.97629607 objectReference: {fileID: 0} - target: {fileID: 6004009293778554413, guid: 1fda7fccaa5fbd04695f4c98d29bcbe0, type: 3} propertyPath: m_LocalRotation.x - value: 0.01966123 + value: 0 objectReference: {fileID: 0} - target: {fileID: 6004009293778554413, guid: 1fda7fccaa5fbd04695f4c98d29bcbe0, type: 3} propertyPath: m_LocalRotation.y - value: 0.5507691 + value: 0 objectReference: {fileID: 0} - target: {fileID: 6004009293778554413, guid: 1fda7fccaa5fbd04695f4c98d29bcbe0, type: 3} propertyPath: m_LocalRotation.z - value: -0.012979111 + value: -0.21643952 + objectReference: {fileID: 0} + - target: {fileID: 6004009293778554413, guid: 1fda7fccaa5fbd04695f4c98d29bcbe0, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 objectReference: {fileID: 0} - target: {fileID: 6004009293778554413, guid: 1fda7fccaa5fbd04695f4c98d29bcbe0, type: 3} propertyPath: m_LocalEulerAnglesHint.z @@ -443572,7 +443576,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 7134386036058471687, guid: 1fda7fccaa5fbd04695f4c98d29bcbe0, type: 3} propertyPath: followers.Array.data[0].faceDirection - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 7402687028936857164, guid: 1fda7fccaa5fbd04695f4c98d29bcbe0, type: 3} propertyPath: m_LocalPosition.x diff --git a/Assets/Scripts/Animation/GardenerChaseBehavior.cs b/Assets/Scripts/Animation/GardenerChaseBehavior.cs index 7395ea98..a3a632ce 100644 --- a/Assets/Scripts/Animation/GardenerChaseBehavior.cs +++ b/Assets/Scripts/Animation/GardenerChaseBehavior.cs @@ -24,11 +24,8 @@ public class GardenerChaseBehavior : MonoBehaviour tweenRef.Stop(); Destroy(ChaseSpline); var gardenerSpriteRef = gameObject.transform.Find("GardenerRunningSprite"); - //ReparentWithExactWorldTransform(gardenerSpriteRef, lawnMowerRef.transform); gardenerSpriteRef.transform.SetParent(lawnMowerRef.transform, true); - //Vector3 pos = gardenerSpriteRef.position; - //pos.y = lawnMowerRef.transform.position.y; - //gardenerSpriteRef.position = pos; + } void HandleTweenStarted () @@ -47,34 +44,7 @@ public class GardenerChaseBehavior : MonoBehaviour { } - public void ReparentWithExactWorldTransform(Transform objectToMove, Transform newParent) - { - // Store the original world position, rotation, and scale - Vector3 originalWorldPosition = objectToMove.position; - Quaternion originalWorldRotation = objectToMove.rotation; - Vector3 originalWorldScale = objectToMove.lossyScale; - - // First change the parent - objectToMove.SetParent(newParent, false); // Set worldPositionStays to false - - // Then manually restore world position and rotation - objectToMove.position = originalWorldPosition; - objectToMove.rotation = originalWorldRotation; - - // Correct the scale (this is tricky because localScale isn't the same as world scale) - if (newParent != null) - { - Vector3 newLocalScale = objectToMove.localScale; - Vector3 parentWorldScale = newParent.lossyScale; - - // Adjust local scale to maintain world scale - newLocalScale.x = (Mathf.Approximately(parentWorldScale.x, 0f)) ? 0f : originalWorldScale.x / parentWorldScale.x; - newLocalScale.y = (Mathf.Approximately(parentWorldScale.y, 0f)) ? 0f : originalWorldScale.y / parentWorldScale.y; - newLocalScale.z = (Mathf.Approximately(parentWorldScale.z, 0f)) ? 0f : originalWorldScale.z / parentWorldScale.z; - - objectToMove.localScale = newLocalScale; - } - } + }