0

I'm trying to make a 2.5D effect, so I need to change scale values regarding object's y position. The lower the object is, the larger its size be. How can this be performed?

younyokel
  • 327
  • 2
  • 15
  • Possible duplicate of [How to implement linear Interpolation?](https://stackoverflow.com/questions/7343697/how-to-implement-linear-interpolation) – Welbog May 03 '19 at 17:38

1 Answers1

1

The size of an object is inversely proportional to the distance of the object to camera. In your case, you can assume that the camera is at Y=0 looking up in the Y direction and that a standard-size object lies on plane Y=1, the scale will be scale = 1 / object_position_y. Note that this is a very crude approximation of a perspective camera, but you can play around it to achieve a cool effect without falling into more complicated calculations.

  • Hello, thanks for your answer. I need to object be more bigger if its Y is closer to window / room size and be more smaller if it's not. For example how decorative objects move in aquarium in game called Fishdom (Android). – younyokel May 09 '19 at 06:41
  • @EadwineYoun Then you can replace `Y` with the distance to the camera. Would it work for you? – Gilles-Philippe Paillé May 09 '19 at 12:17
  • a Camera? But if the game is 2D? I have window size, object size (0.0 up to 1.0), it's positions. – younyokel May 09 '19 at 17:29
  • When I say camera, it refers the your concept of window. Your object has a Y value. Use it as defined in my answer, i.e., `size = base_size / object_position_y`. Put your object at `y=1` for the regular size, and increase `y` to make it smaller. For example, at `y=2`, the object will be two times smaller. – Gilles-Philippe Paillé May 09 '19 at 17:36
  • 1
    thank you very much, that worked, I clamped the scale and multipled the size for 2 because the changes was minor. `size = (base_size / y) * 2;` – younyokel May 09 '19 at 19:29
  • @EadwineYoun Great! Glad that I could help you :) – Gilles-Philippe Paillé May 10 '19 at 00:34