Building an XNA Game Studio XBox360 Indie Game.

[page 0056] ~ When In Doubt:

Updates – .

The theme is still NEON.

When in doubt, read the instructions.  And so, off to where it all began, kinda sorta, for me at least, something more like the near of doing Xbox C# stuff in the past and not so much as the far off of the c++ past, and definitely not the really way back BASIC past, for the most part, I think.

Well, the Unity Project: Roll-a-Ball reminds me of the MSDN FuelCell Example Game which uses the MicroSoft XNA Game Studio 2010.  I also found this, Unity Third Person Control: Camera Follow – Tutorial 7, which is a multi-part tutorial that runs a character around using an XBox 360 Joystick Controller, my favorite means of game input.  Currently I’m using the afore mentioned controller that is connected via the USB Wireless version to my PC.  Using this, the PC can take up to four controller inputs simultaneously.  The wireless models let the XBox 360 connect up to four controllers concurrently, if the game is built for that type of allowance.

And so, not only is this game going to be focused on neon, but also on getting a camera to follow the game character around the game, correctly.  This simple game, FuelCell, uses the XBLIG Vector3 class to define its usage much like the Unity Vector3 class.  Both of these game platforms with, XBLIG FuelCell and Unity Roll-a-Ball, use the class GameObject as a binding structure to consolidate its game pieces and be able to reference them, by a named tag, as a component from within the contents heap of the game.  The FuelCell game builds the GameObject as a simple class to hold the 3D models, load content and bounding sphere, its draw transforms and lighting effects, input and movement routines, collision detection and camera placement in relation to the Avatar, seen as multiple classes all within the same code page,  with name spaces, using statements, class constructors, definitions and declarations, methods and functions, accessors and mutators for public and private properties, etc., all written in C# code in text.  Unity uses GameObject in much the same way except for the fact that the game engine adds the protocol and code “Under the Hood” behind the API in a black box fashion as Components, with a single click of a button, where the public access of its variable contents are seen in the Inspector tab and where extensions that connect the objects and variables can be implemented through a scripting language.  What I will be dealing with here as I move through both of my XNA Game Studio and Unity games will be an old school new school thing.  It’s kinda like what XNA was to DirectX back in the day, a wrapper that simplified the coding of broiler plate templates to initiate the start of getting something to begin to become what was intended to be needed, for the actual task, required, to get ready to …  Well let’s just say it was a long hard road to go from a computers system space to go to a games name space.  But the concepts are all much the same although the simplicity of implementation has grown in complexity to encompass what is now seen as the Unity Game Engine, XNA is pretty much the same thing but without the walls.  Sometimes walls can be nice, and a roof, and some plumbing, and … but it is good to know how it all came to be, fits together and why.

So every GameObject has a Transform, in either case, so each piece exists at a specific location in the game.  Now to take a look at how the XNA FuelCell is put together and try to compare it to the Unity Roll-a-Ball so my game, Neonlithic, can get done and submitted.  The XNA Camera uses an offset from the target to position the camera back and up from the target to look back down at an angle.  These values are given to the View Matrix and Projection Matrix which are in turn given to the World Matrix which is drawn to a 2D screen space.  Back in Unity I need the offset to remain constant in relation to any rotations that are given to the target, i.e. the Avatar.  OK, MonoDevelop has a “find all references” to see where and how all of the variables are placed and used, that’s nice.  What I need to do is get the Avatar to rotate in a direction and then give it some forward velocity to make it move, in that direction.  The camera also needs to have the same direction and velocity, and then to find how something else works so that it moves more like a chase camera.  Something like having the camera placed behind and up to become an offset with the cameras’ LookAt point being the Avatar.

And that is where I will be going next, Chase Camera.  I already have the XNA Game Studio installed and loaded up.  I also have the Chase Camera downloaded, unzipped and running.  Chase Camera is one of the code samples that I used to build HUD-On and will hopefully become of help again with Neonlithic.  Well it looks like, for this game anyways, I’ll get the direction that my Avatar will move towards from an ol’ quick and dirty trigonometric function.  Using the left and right buttons of the mouse, I’ll get an input register from the FixedUpdate() to count at an increment and decrement for either button.  This will give me a positive or negative number which I’ll give to a Quaternion.Euler to build a new transform.rotation from my target. After that I’ll take the .y of the transform and change it from radians to degrees.  Giving this number to both the sine and cosine functions I’ll multiply it with the forward velocity and give it back to “movement” which is the force added to the rigidbody component of my Avatar. Eeek, but it makes enough sense to move my game piece around the board so the controls seem to do what is intended.  Now I need to get that camera to follow suit and follow my Avatar.

That’s interesting, the Debug, DrawLine and DrawRay act almost the same when the second Vector3 argument of Line has its value of the character position added to the direction, without it, the DrawLine function does some really weird curly-Q stuff on the screen.  Another thing is that the Ray points directly out horizontally while the Draw has its second vector pointed towards the ground, one more line and it would become a triangle, but for now its just an angle. Debug.Draw and .Ray are really good features for testing and research. But I need to get this chase camera thing hooked up to my Avatar.

Or, I could go back to what I usually do and add some text to the screen, although I have some text running in the Debug Console now.  And the text will be a compass with the direction in degrees that the Avatar is facing.  Simple, but how do I add text to the Unity screen.  “7. Displaying text” from the Roll-a-Ball tutorial gives me enough insight into and direction for me to get my faux-magnetism of this games rather flat terrain displayed as a number between 0 and 360, where 360 becomes 0 again.  One thing that I find very strange is that little deadened “ding-bonk” is missing for all the mistakes that I make when the Unity scripting compiler, which gives me my error messages, finds an error.  I’m having some phantom error message sound beleaguerment going on in my head.  So guess what I’m working on right now, that isn’t doing exactly what I think should be happening, with many scripting errors.  I need to get the camera hooked onto the end of where the Ray is positioned, but I can’t figure out how to get one variable from one script in the Player object into the Camera class to be used by that script, “ding-bonk” (Red Stop Sign Exclamation Point) error message, “ding-bonk” (Red Stop Sign Exclamation Point) error message, “ding-bonk” (Red Stop Sign Exclamation Point) error message, hmm.  Well, at least there is some constructive and safe feedback and not a blank stare of Oh-No, where I’d be lost in lah-lah land with the blue screen of death and a hopefully successful reboot, without a loss of data.

With a little bit of searching I have found “20. GetComponent” that explains well enough, for now, how to get properties from a script to another.  And there is another somewhat odd feature in Unity, where, when scrolling the mouse all the way across the screen while holding the mouse button down to change a variable, the mouse will reappear on the other side of the screen and continue to scroll the variable, rather handy, indeed.  Hmm, it seems that Unity has no Vector Line Drawing capacities or anything that I was used to doing in Processing.js, which was a whole lot of vector drawing, or something like it.

I think that I’m starting to figure out the way that their textbox drag and drop stuff works.  It seems that what it is doing is making a reference to an object and therefore its properties.  The other option is that it is that it is copying it by value, to then be worked on further, which seems unlikely.  When accessing an object “By Reference” what is happening is that the memory space allocated to that object has a residence starting at some memory value and continues to fill that memory space until the end of the objects length.  Many things can access that object by reference and if it is changed, then all forthcoming requests for that objects properties or actions are also changed.  “By Value” is when a completely new copy of that object is made, and subsequently uses up another objects worth of memory space, so twice the space is used but the are two separate objects that will perform differently.  But how does this help me.  I just deleted the Main Camera and placed it in the Avatar object to see if that would make accessing the rotation any easier.  What I’m trying to do is take my sin and cos values I get from the mouse buttons and change them back into a rotation for the camera.

That makes no sense, why would a rotation transform for an axis not be used to move that object in the direction that it is facing.  The camera rotates in a direction to “look” in that rotation but how does the forward velocity become altered so that the LookAt direction is the new forward and therefore taking on the roll of forward velocity.
OK, I have something that moves the Avatar forward and backward while pressing the w and s keys and then comes to a halt when the keys are no longer held down, that is my forward velocity.  Now I need to have that velocity distributed throughout a Vector3 so the forward velocity is relative to the rotation of the objects transform.  OK, so I need a Vector3 force influenced by the transforms rotation of the y axis, possibly a torque value.  And, per usual, what is observed as obvious becomes the complete antithesis of what is needed and provided.  It’s as simple as the Kata in Karate, first you look in that direction, then you strike, block or evade using that side of the body that you moved your attention to.  So my Avatar must look in the direction that it will be going, then it will take that as the new forward and move in that direction.

Well, I’ve got a camera that pivots around the Avatar even while it moves forward, which is the only direction that it can go, for now.  I’m getting there.  Instead I need the camera to always point forward as the Avatar changes its position on the playing field.  Hmm, just a lot of flailing about with EulerAngles, LookAt and other Quaternion things.  But what I haven’t been doing lately is making script Back Ups so when I get to a place in time that things are working correctly I’ll be able to paste the back up back into the script and start over with a stable working model.  The only draw back is that there may be more objects that have been added to the game engine that are dependent on some of the variables in the previous script that wasn’t working all that well, but that bridge will need to be crossed when I come to it and if it is ever reached.  Until then, it’s time for a back up save of this C# script.

Blah de-Blah, I have a rotation in the y axis.  I need an x and a z value for my Avatar rigidbody.AddForce so it has an argument value being a Vector3 made up of (x, y, z) where y = 0.0f, no voluntary jumping, and the x and z are comparative to width and depth of the game board, no need for the y axis because this Avatar is stuck to the ground.  When I go forward, my y rotation in degrees is 0.0 and, Hey Hey, it works!  Time for another save.  Hmm, but after moving around for a short bit, like about ten seconds the screen starts to shake and then the screen begins to spin in a perpetual loop, until the stop debug button is pressed.  So what am I missing here.  That fixes it, in Rigidbody/Constraints/Freeze Rotation, I needed to check all three X, Y, and Z boxes.  No shutter or recursion spin.  Now to tidy up and off to #1GAM.

And that is that.  Not the best game in the world, but it is a slightly better or at least a more Neonie version of Roll-a-Ball with a hint of FuelCell.

Your Avatar must collect the eight neon stones that have been thrown about the map, as they sparkle their neon shower.  They will soon disappear but don’t run your Avatar so fast as to fall of the edge of the world.

Controls :

A-W-S-D keys and Up-Down-Left-Right arrows move the Avatar in those directions.

Play NeonLithic Here.



April 2, 2014 - Posted by | 2014 [0050] to [00??], The Process | , ,

No comments yet.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s