Saturday, January 21, 2017

TOE week 21: Complex road to a simple solution



I was feeling out of practice when I opened up Visual Studio for the first time in a while. A lot of the code work has been done. Not that this here thing is even close to done, but right now I’m working on the art stuff. So imagine my surprise when I tried to program something that should be a complete cake walk and nothing I did remotely worked. 

Basically I need to have two backgrounds for my game. Because they are backgrounds they need to move with the player in the X and Y directions but not in the Z direction. I remembered in a different game I made from a YouTube tutorial that you could lock an Axis. Meaning that an object would not be allowed to move on a locked Axis. This didn’t work with what I was trying to do because the Backgrounds are not moved because of Ridged Body(a property in Unity). These Backgrounds were instead attached to the Player and move relative to the Player’s position.  If the Player moves in the Z the Backgrounds do the same. Meaning that you could never see the farthest Background because the closer Background always covered it.

So much of programming is Syntax. Have I said that before? Because it is so freaking true. People for the most part are Syntax free. Ask your friend to ‘move cup’ and generally they can look at the table and extrapolate that you want them to pick up the cup on the table. A computer on the other hand will stare back at you and say “error expected: definite article”. 

When I ‘asked’ the computer to set the transform.position.z of the background object to be equal to ALWAYS be equal to its starting Z position the computer said you can’t do that. I fought with it for awhile. More like I tried to trick it with various ways for a while. None of that worked. My brother in law called and I complained to him about my problem we laughed. When I went back I deleted everything I had tried to do and started from scratch. 

Then I basically found out that I was asking the computer to do something entirely the wrong way. 

transform.position.z = stickingPointZ is not legal. 

You have to define a new Vector and set that vector to be equal to your variable. Basically transform.position.z is part of a vector and stickingPointZ is not a vector it is Float. So they don’t like talking to each other I guess. 

transform.position = new Vector3(playerPointX, playerPointY, stickingPointZ);

It is a simple solution but it was complicated getting there. Then I spent the rest of the week painting after I figured out that small problem. After I had finished my BG I plugged it in and bam suddenly my game was like 50 percent more presentable! Next week I have to paint the other background and we will have something that is closer to looking like a game.
 

My game with a background!


 The background.

No comments:

Post a Comment