Friday, August 26, 2016

TOE week 12: Unrefined Ducking



                I didn’t want to work on the game this week, for two different reasons. First reason being I was sick. Wife went back to work found new germs and the house got sick. So I spend Monday curled up on the couch binge watching Stranger Things and eating hot soup. Second reason being I thought that implementing ducking would be hard. Was I right? Kind of but not really.

                I have this fancy Ray Cast system set up for the player. Basically my player sends out a Ray and the distance of the ray determines the player’s speed.  So if the player is colliding with a box the distance of the ray is zero and so the player’s speed is zero. But the hit box I have representing the player is basically the player’s feet. So I needed to double the player’s height and add the player’s head, ‘so to speak’. This seemed really complicated to do. I knew how I thought this should work but making it and thinking about it ARE two different things.

                Well turns out that I just needed to add the player’s height to the Y calculations up for Ray Casts in the position Y direction. Negative remains the same. And then increase the height of the X direction and suddenly we are Ray Casting with everything covered! I do need to better look at this because it was some hack code to accomplish this but it does work.

                Then it was just a matter of moving the player’s head to the position of the player’s feet in the Y direction when user input is negative for Y. Setting this up caused I bug that I haven’t quite figured out yet. Basically the bug goes something like this: nine times out of ten ducking works as expected. Player presses down and head.Y is equal to feet.Y. Then there is the one time when the head.Y is -1 lower than feet.Y. So it creates a situation where you have crouched SO low that your head has fallen through the ground.  As a tester inconsistent bugs were slightly annoying but as a dev they are the WORST. A game is made out of so many variables and tracking down the one thing that one thing that broke everything is a pain in the ass. 

                There are other things not quite right with ducking at the moment, like you can move left and right while ducking. So I have imperfect ducking at the end of the week. I mean it was less of a head ache to set up than I thought and I have a rudimentary version actually working, so overall I will call it a B-! 

                The thing I set up earlier in the week before ducking was wind tunnels and treadmills. Basically a vector that pushes the player in a direction when they collide with this type of collision. This was something else that I thought would be difficult and turned out to be REALLY easy. I slapped on some classical music and in about an hour I had it working rather well. Then two more hours and it was refined push collision. Maybe by the time next week rolls around I will have refined ducking? Who knows. 

                I think I am about ready to start arting this here game thing. Maybe slap some pretty pictures on this and finally show off what it is supposed to look like! Oh I guess I have to make those pictures. Going to close with a video of ducking and push collision. 

 




Thursday, August 11, 2016

TOE week 11: No 'real' progress still = progress.



                Last week I was complaining about Get Component calls and how confused I was about them. The next day I had another light bulb breaking moment where I watched a video on Unity by Unity on Get Component and I finally saw it. I saw what I was doing wrong. Then everything made sense. Part of my problem was I was not thinking about a Get Component as a variable. 

If(!Blah){
                Int aNumber = 7;
}

While(Blah){
                aNumber = 10;
}

                I knew you couldn’t do the above. Basically the variable aNumber only exists in the above if statement. When the compiler leaves that statement that variable dies. So last week when I was asking why doesn’t Update know about the Get Component call from the Start function it was because I was doing the above. Trying to set the value of aNumber in a function where that variable had ceased to exist. 

                But when I figured out where I was going wrong worlds kind of opened up. I went back through a fair amount of my code and corrected my wrongness. Nothing really changed about the game after this fix. The frame rate didn’t change but the code is more optimized right now. Also knowing how to set it up right means that I will set it up correctly going forward and that is a good thing. 

                Also  in my quest to do things that show no ‘real’ progress I put in all of the code for input from a game controller. Right now my game can be played with a 360 controller. Before this it was all off of keyboard inputs. Again nothing has really changed but I find this to be super cool. 

                Anyway I have been meaning to post a video of what I actually have going on right now. So enough talk, watch this video of me playing my game. 


TOE week 9 and 10: Showing Off and Doing It Wrong.



                I was on vacation again this week so I didn’t really do a lot. Aside from show off the game to various different people who I could subject it to. I did however get a working primary attack set up. Last week I set up some targets that would take damage when hit but any of my secondary weapons. This week I set it up so the targets will die after they run out of hit points. The targets are supposed to give the player ammo when they die but I didn’t have a set up for player ammo being deduced when a secondary weapon was used. I added a player ammo counter and a restriction that prevents the player from using a secondary weapon if they don’t have any ammo. Once that was set up it was pretty easy to add into the on death for the target to give the player ammo when the target is destroyed. 

                Next week I need to add in a basic UI for Player; health, current secondary weapon, ammo and can teleport. I also wanted to make a video of what I currently have. But I think that may have to wait until next week. It hasn’t really been a big week but I did get more done than the last time I was on vacation. 

                Hey look it is next week. I didn’t post this last week partly because I was on vacation and partly because I didn’t have a lot to report. I kind of still don’t BUT I did add in all of the UI elements for Player stuffs. I did find some small bugs with my can teleport bool. Basically if my top raycast is not touching collision but the bottom raycast is touching collision the can teleport bool is true BUT the player can’t teleport. Super minor. It is certainly something that needs to be fixed but for the most part it works. The issue is clearly not with the UI and more with the teleport testing method I’m using. I need to change this test to an onOverlap instead off of four rayCastHit.

                So I’m going to complain about getComponent call once again SHOCKING I know. To make my UI work I have four Canvas elements that each monitors four player variables. I have seen on the internets in my research on this topic that you should never use a getComponent call every frame it will slow your game down. This was the only way I could figure out how to get the UI to update when the player variables changed. However there was no slow down when all of them were updating. Basically my update for UI stuff looked like this: 

Update(){

GameObject thePlayer = GameObject.Find("Player");
Player playerScript = thePlayer.GetComponent<Player>();


displayPlayerAmmo.text = playerScript.playerAmmoCount.ToString();

}

                Again I have been told that this is terrible but various Unity people on different Unity forums. But how am I supposed to display and monitor variables from the player in the UI canvas? No seriously how does one do this?  I had a thought and it was this: 

Update(){

If (hasGotten == false){

GameObject thePlayer = GameObject.Find("Player");
Player playerScript = thePlayer.GetComponent<Player>();

hasGotten = true;

}


displayPlayerAmmo.text = playerScript.playerAmmoCount.ToString();
}
                However THAT doesn’t work because GetComponent call only seems to pertain to the method you are currently in. Meaning that Update doesn’t know about playerScript. Only the nested If statement knows about the playerScript. 

                The wife goes back to work next week and I will have less time to devote to this thing. So my Updates might be shorter. I think I need to switch to working on more of the artwork as that is something I can do at the same time as being a stay at home parent much easier than programming.

               

Friday, July 29, 2016

TOE week 8: Super Parabolic Light Blubs Breaking Over My Head!

                So much of being a programmer seems to be figuring out just how to get the syntax to work for you. When I still worked in industry I remember that many of the Engineers had three or four books on their desks at all times. I understand why more now. Often half of the battle seems to be leafing through Unity’s website and looking at example code and then saying, “Oh that it what this it for!” 

                Then there are other times when really easy things are hard. I spent an entire laptop battery trying to figure out how to get the angle of the trigger object that my secondary weapon hit. I used my Google fu to try to find out how to do this and because I was using ontrigger instead of oncollision this actually seemed impossible to correctly set up given what I found. Fine! I will use oncollision and make this secondary weapon use Unity’s physics. And that worked I could get the angle BUT because I was scripting the motion of the object and Unity’s physics was making the thrown object move in some super crazy ways. The thrown object would sometimes fly off of the Z axis entirely. So the final result was right but the trip to the result was just wrong. 

                This was like probably two hours of trying and checking. Then someone broke a light bulb over my head. Wait can’t I just col.Transform.rotation? OMG! I felt like such an idiot for it taking me THAT long to figure out something so damn simple. But then I saw it working and felt like such a champ for making it work. The jury is still out on what is what. 

                Last week I set up some crappy looking secondary weapons. Well two of them where crappy the first one is still fine. I was reminded of something my animation Professor in college said. “When the animation moves, you will feel amazed. Don’t ever lose that. But the next step is then asking, how do I fix it?” When I showed my wife who is a Physics teacher what I had set up and told her that this weapon was supposed to be a parabola. She showed me how to make parabolic motion work using an equation. We had one small hiccup with me not knowing the Time.Deltatime is not the entire time an object’s existence and hence not equal to elapsed time. After I had created an elapsed time variable it was super parabolic! 

                Sending a message through objects in Unity is kind of crazy. Or I should say that when you have a target that can be hit by five different things but don’t know which object hit the target, it seems kind of impossible. Or I could just use the built in function SendMessage in Unity then passing values between objects that don’t know about each other is actually completely possible. It really boils down to, 'do I know what the information I need is called?' My Google fu for this was ‘dealing damage in unity’. Found lots of things that were less than helpful. Eventually found a really helpful tutorial. The tutorial wasn’t even in C# but I was able to convert the Java to C#. That is how far I have come! I really still can’t claim to be a master programmer but I seem to be figuring it out. The end result was this though. I now have 4 secondary weapons that all can deal damage to any object that is tagged as a Target. Pretty freaking neat!

                Trying to find a way to pass messages between objects took even longer than trying to figure out of to get an angle of a slope that a was hit. I think it took me 3 hours to figure out how to get that angle. It took me 6 to find a good way to talk to objects that don’t know about each other. But again allow me to once again say this is insanely fast! Unity is still stupid amazing!

Friday, July 22, 2016

TOE week 7: Secondary Weapons and Secondary Priorities



              This week I managed to implement 3 secondary weapons. Aside from a couple of Google searches to tell me, ‘just how do I use this syntax?’ everything was pretty easy aside from new things I broke. I also colored some pictures for the other project that I am still trying to finish. I now have some Blender work to do to finalize the background of the image. This week wasn’t a good week for the game but it wasn’t a bad one either. More down the middle. 

                My three new weapons are basically a gun, a boomerang, and an angry bird. They don’t all behave correctly at all times. But that is standard fair as I have seen of late. The angry bird a parabolic based weapon works great until I cross over the  0,0,0 mark in the world and x is negative, then it decides that it doesn’t need to fly up anymore. There is something fishy about this. I will have to look into it and find out how to kill this problem. 

The gun and boomerang went off mostly without a hitch. Guns in a 2D platformer are pretty simple. Send object that way then destroy object when too far away. Aside from the problem that when wall sliding the secondary weapons are shot in the direction of the wall the player is stuck to… Really minor but wrong. I could nix this real fast by saying you can’t fire a secondary weapon while wall sliding but I haven’t decided if I want that or not. Firing from a wall is actually kind of cool. Think Megaman X. 

I still don’t love the Get Component calls in Unity C#. I wish I could just say hey these two attached objects should know about each other’s public variables. I guess that is what a Get Component call really does but it is clunkier than C++. Really though that is the only thing that Unity C# is clunkier than C++ about. 

I haven’t been able to work as hard on this project this week or even on the other project. I am the stay at home dad again. But as of end of day today the wife is on Summer Vacation again so I can put in more time next week maybe… I say maybe because we have A LOT going on next week with my son’s doctors visits. Our free days are rapidly disappearing. Not for fun cool stuff either. Also this week I focused a fair amount of time into fitness and was just too damn tired to work on anything game related as much as I should have. 

I had some delusions that I could hammer out this demo before my wife went back to work in August. YEAH that really doesn’t seem likely now. Sigh. Delusions of grandeur I suppose. I am also going to visit more family in a week and I really want to bring my Laptop to show this off to people. I regret not brining it for our last trip but there wasn’t enough room in the car and I didn’t want to crush the thing. 

Next week I might have to put in some targets to hit with my fancy new Secondary Weapons. I also need to find a way to assign what weapon you’re using. Like pick up a gun and drop the boomerang.


Friday, July 15, 2016

TOE week 5 and 6: The Hardest part is actually the Easiest part.



Last week was a bit of a wash, I practically did nothing. I was on vacation without my laptop we had limited room in the car for our trip and my laptop is bulky and I didn’t want to crush it or something. I did draw for about fifteen minutes and it was a crappy drawing so it doesn’t count. There was some good however one of our friends down south is a Graphic Artist who took a look at my entire sketchbook and he liked my designs for this TOE project that I’m working away on. He did point out a few things for my boss designs but overall he liked my art. I don’t think I have had someone look through my entire sketchbook since I was in college. It felt good. I also got to have my sister in law, brother in law, nieces and nephew play the game a little bit when we got back home.

I know that I said I was going to be coding for awhile but the latest assignments have be art related. A while ago I made Halo armor out of card stock and fiberglass resin. The part I was most looking forward to was painting the armor. That was basically my favorite part of that project. One of the other projects that I am stupid close to putting a bow on needs me to ‘paint’ some things. I was actually excited about that part. The part that I didn’t want to do was scan the drawn artwork from my sketchbook. 

                I can’t even say why something so insignificant was preventing me from doing something that I actually love to do. Twain doesn’t work in Photoshop anymore unless it is 32 bit and my scanner doesn’t scan at a resolution that I’m happy with not because of the scanner but because of the only program that works with the scanner on Windows 10 maxs out of 300 dpi. Not bad really but all of these things combined made me really hesitant to attempt even scanning anything. I had been meaning to just scan some drawings since Sunday. I just did it TODAY. I also got around to painting one of my drawings TODAY as well because I finally scanned it! I also did scan in a landscape piece from the sketchbook that was supposedly for this project. I don’t know if it yet fits but it was something that I promised last blog. 

                So no new code, no secondary weapons, no animations… I have to finish the stuff for the other game before I can put more attention onto this project. I am going to try to finish most of that stuff this weekend. It is all scanned now so the hard part is over…

                Going to shut up now and post these drawings.