Lawnmower Chase Work
Gardener chases but gets flipped
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user