Hey,
im making a point and click game with 2d pictures. I want to make my player smaller when he goes up the picture (or y coordinate) to create a realistic feeling where it feels like the player is moving away from the camera.
im pretty new to scripting so i dont really have a clue… but i thought about something like when the y coordinate of the player is increasing the y.scale should decrease but i dont know how to realize it?
Hello there.
Then you should create a function inside the update (so its exected every frame) wich controls the scale of the sprite.
You should find the relation between the y position and the scale. For start, you need to know the transform.position.Y coord (I supose is Y coord but if you rotated the camera can be any other comoponent) of your character. Lets say, the Y value can go from +50 (top of map) to -50 (botom of map). And when is at top you want the sprite to be 125% of its original size, and when its at bottom, at 75% of original size. Then assign a multiplier to the scale of the sprite, (Scale is a property of the Transform component of any object).
Some code like This:
void Update()
{
// Original Scale is always 1
// Scale is a vector, so you need to change all its components to mantain the aspect ratio)
int ScaleValue = 1-(TheSpriteObject.tranform.position.y/200);
TheCharacterObject.transform.scale = new Vector3 ( ScaleValue , ScaleValue , ScaleValue );
}
So each frame will be calculating the scale of the character.
This way, when position.y is -50 scale will be 1.25 (125%).
When position is +50, scale will be 0.75 (75%).
You need to find your way to get what you need. This is not about knowing commands or functions. Is about thinking.
Good Luck!
Bye!"