I didn’t post last week at all, but that’s not to say I wasn’t working on the game at all. I spent a good amount of time making the room builder easier to use by adding a toolbar to the top. Prior I had keyboard shortcuts.
I then started the task of adding perspective scale to walk boxes. The higher up on the screen I want the player to look further away, smaller and move slower. There are a couple ways to handle this. You could just scale the player via it’s Y position, however I want a little more control than that.
I tried adding a scale value to each walk box, so as long as the player was in that box, he would be that size. However that didn’t work to well because there wasn’t a good way to set a speed to uniformly scale the player when it crossed a border to the new box.
I changed methods and assigned a scale value to each corner of the walk boxes. The closer to the corner it gets, the closer to that scale it gets. It took me a lot of experimentation to get it working. It still has some weirdness to it, but as long as I follow a few rules, it works.
Each walk box can only have at most 2 scale sizes in it. This means I am limited to using rectangles or triangles. If I add more points or scale sizes, it jumps up or down to different scale sizes too rapidly when it changes to a new closest point. I’m sure there is a way to somehow average some values together of all the points or something to get a smoother transition to use more corners, but I’m bad at math and this seems to work so I’m going to move on to the next thing.
I actually did try averaging the scales between the closest corner and all the other corners but that had the effect of shrinking the player in the center of the box and growing him along the edges, which kind of makes sense.
The method I am using to determine the scale is the following:
- Get the closest point to the player and second closest point to the player with a different scale value
- Get the difference in scale between the two
- Get the distance between the two on the Y axis
- Divide the difference in scale by the distance
- Subtract that value from the larger scale size
- When the player walks, multiply the scale by the speed that I’m moving it so that it moves slower when “further away” from the camera
In the video below, the blue line drawn is the distance from player to the closest corner, and the red is to the second closest. I set the scale values pretty drastically different for testing purposes so you can really see the scale changes. At the top of the screen the scale is .5, and bottom of the screen 1.0 – In the actual game, I don’t think they will be so drastic.