# Warp GameObject Size When Entering/Leaving Area

Below I have an image describing the desired functionality I am going for. Let's say you control a square and when you move this square into a given area, any part of your rigidbody/model inside of the area will be magnified upon entering and shrunk upon leaving. So now you more or less are made up of two rectangles, one small and one large.

What would be an elegant approach towards achieving this effect?

• Are you using Unity? Aug 16, 2014 at 4:29
• @TrevorPowell I have not implemented anything yet because I was afraid my approach would be overkill. I was initially going to have the object's transform be reinstantiated on every update based on where the intersection of the player and the area was. So initially we are made up of one rectangle and then right when we enter the rectangle, we destroy that initial rectangle and make our new object be comprised of a smaller rect representing the left side and a larger rect representing the part that has entered the "magnification zone". Aug 18, 2014 at 14:38
• @AssortedTrailmix Yes I am using Unity. Aug 18, 2014 at 14:38
• Then using multiple gameobjects with physics will be impractical Use the camera approach, possibly with an image effect to further the illusion of a "magnifying glass" Aug 18, 2014 at 14:44
• I like the idea. However, for my needs I think it may be too limited. The game is multiplayer and in some cases, one player walking into the zone will only cause him to grow in size while the other player walking into the zone will not do the same. Essentially, this transformation is not an illusion but actually happening in the world. Aug 18, 2014 at 15:03

You can't do that with physics very easily (if at all).

A much simpler solution would be to use a second camera and calculate the viewport. The psuedocode would be something like:

if(magnificationCameraGO.IsVisible)
magnificationCamera.enable;
magnificationCamera.pixelRect.x = ConvertGameObjectPositionToCameraPosition(magnificationCameraGO.position.x)


You'd place the magnification camera on a gameobject, and position that gameobject where you want the magnification to appear

• This would be my initial suggestion, try it out! Sep 17, 2014 at 15:22