Over the past couple days I decided to work on camera controls and player movement. I wanted to get this done so what ever I work on next will be more enjoyable for me to roam around in or look around at(since I like completing visual goals).
I first wrote a simple script in C# that allowed me to move a box with the W,A,S,D keys. I first version of the script just moved the transform using Vector3 calls. What I mean by this is the transform would just move instantly one space in whatever direction I told it to. This was basic movement but it would not work for my final product. Deciding this would not work for me, I went to the internet and found a simple script on the unity reference pages that allowed me to move my cube much like a car. Using forces this allowed for acceleration and smoother movement. Again, this eventually was not I wanted but it was fun getting something to move and learning more about Unity and scripting. I dropped this script completely and decided to start over!
Camera
When I decided to work on a new movement script I started with my camera. For my game I want to have a third person camera. I like third person and I find most of the games I play are in third person. I made a list of the camera features I wanted and started working on those.
Camera Features:
-Zoom In/Out
-Rotate around player
-Follow behind player while player is moving
-Snaps to player when character decides to move
-No clipping through floor/objects
With this list in mind I started with the Rotate around player goal. There are several great references online that allow me to get a simple script up and running in no time. Of course, I needed to change a few parameters to make sure the camera fit my needs. I think in about an hour I had a camera that would take a transform target and allow me to move around the player with certain restrictions(like not completely under the player). At first, to rotate the player, you had to use the left mouse button but I changed to allow both or one of the mouse buttons using an "or" statement. Next I worked on the Zoom function. I wrote the code so the player can use the mouse wheel to zoom in/out at their will. After a few hours, I had a camera that followed the player and allowed me to look around. It was awesome I was so happy. The next task, no clipping, was a different story and at first I said "screw it."
Jumping, Spinning, Walking, Running, and "Strafing"
So I decided to skip the camera clipping function and move on to player movement. I went online and found a free character model with some basic animations. I wanted to have something visual to look at. To start with character movement I looked at unity references online and decided to use a character collider for moving. There are two functions for them "simple move" and "move." I use "move" for my script since it allows the most options. I also used the Input Manager that Unity has to keep track of all of my controls. I started working on moving forward and back and rotation. That was simple. I just applied the values that are returned from a ButtonDown command and put thoses on the which axis I needed for that movement. I also worked on making sure the player model had to be on "ground" first before these movements could work. For running, I added a speed modifier to allow me to move faster when I toggled a button. Jumping was a little more complicated. I checked to make sure the player was on the ground and then I added a timer so the player could not continually jump. This took me some time to get working and I still am not perfectly happy with it but its not bad right now! I have strafing working but it does not look good with the animations so I will probably work on it more when I get a better model.
Right now I am working on a Season Script so I can make changes to the Game Time script. I want to change how bright the sun can get and how long the days are and maybe add particle effects later or wind. My next post might be about that but I do not really know!
Dan
Saturday, March 16, 2013
Thursday, March 14, 2013
We have Day and Night!
Today, I worked on getting a day and night cycle running for my game(I like working on visual things first, it is more rewarding!). I am pretty happy with the outcome. I will go into more detail below but here is a brief summary.
There are two scripts used for the day night cycle. One controls the sun's properties and the other controls the time of day and rotation of the sun. The in-game day can be however long I want it to be, it is changeable. I can keep track of how many in-game days, months, and years have passed. The sun's rotation speed depends on how long the day is. I also added a Skybox that changes depending on the time of day. The time of day, for now, starts at 12pm and lasts for 30 minutes.
Detailed(With Pictures!)
Ok, so I started out writing a general script to keep track of time and to rotate a direction light in Unity. I use Time.deltaTime and store it in a variable and use that to keep track of days, months, and years. I use a simple Transform rotation to rotate the direction light on the x-axis. At this point the light rotates around the scene like an actual sun.
Fig 1: You can see the direction light in the upper right-hand corner. It is rotation and projecting the light flare on the lower left-hand corner
I wanted to have a more detailed system so I continued coding. I wanted to change the brightness of the sun every day and I wanted to add a Skybox.
To get different brightness settings every day, I created a script for the direction light. The script sets random values every day. The Game Time script I wrote earlier uses these values and adjusts the sun's brightness based on the time of day. For example, at noon or 12pm, the light is the brightest and as the day goes on it gets less bright. I really liked how this turned out and as little as the random values of brightness change I like the added effect.
Fig 2: This is just the direction light(sun) setting.
The Skybox at first was just one scene with clouds. I did not like it so I went online and found a new shader that allows me to add two scenes. One scene is a night sky and the other is a day sky. Using this new shader, I code in the Game Time script how it should blend the two scenes by time of day. I really liked how this turned out. I think it is beautiful! I feel like the world is coming to life, even though there is no world, yet!
Fig 3: The day scene skybox. The cube shown is to look at shadows.
Fig 4: The night scene Skybox. The cube shown is to look at shadows.
Side Note:
I added a moon with the same functionality as the sun but I did not like it so I did not keep it in my final setup. I like the night sky too much. Also, with my Game Time script I can add events depending on the time of day!
I will try to keep my thoughts organized on these posts. I cannot promise though. If anyone has questions, ask away!
There are two scripts used for the day night cycle. One controls the sun's properties and the other controls the time of day and rotation of the sun. The in-game day can be however long I want it to be, it is changeable. I can keep track of how many in-game days, months, and years have passed. The sun's rotation speed depends on how long the day is. I also added a Skybox that changes depending on the time of day. The time of day, for now, starts at 12pm and lasts for 30 minutes.
Detailed(With Pictures!)
Ok, so I started out writing a general script to keep track of time and to rotate a direction light in Unity. I use Time.deltaTime and store it in a variable and use that to keep track of days, months, and years. I use a simple Transform rotation to rotate the direction light on the x-axis. At this point the light rotates around the scene like an actual sun.
Fig 1: You can see the direction light in the upper right-hand corner. It is rotation and projecting the light flare on the lower left-hand corner
I wanted to have a more detailed system so I continued coding. I wanted to change the brightness of the sun every day and I wanted to add a Skybox.
To get different brightness settings every day, I created a script for the direction light. The script sets random values every day. The Game Time script I wrote earlier uses these values and adjusts the sun's brightness based on the time of day. For example, at noon or 12pm, the light is the brightest and as the day goes on it gets less bright. I really liked how this turned out and as little as the random values of brightness change I like the added effect.
Fig 2: This is just the direction light(sun) setting.
The Skybox at first was just one scene with clouds. I did not like it so I went online and found a new shader that allows me to add two scenes. One scene is a night sky and the other is a day sky. Using this new shader, I code in the Game Time script how it should blend the two scenes by time of day. I really liked how this turned out. I think it is beautiful! I feel like the world is coming to life, even though there is no world, yet!
Fig 3: The day scene skybox. The cube shown is to look at shadows.
Fig 4: The night scene Skybox. The cube shown is to look at shadows.
Side Note:
I added a moon with the same functionality as the sun but I did not like it so I did not keep it in my final setup. I like the night sky too much. Also, with my Game Time script I can add events depending on the time of day!
I will try to keep my thoughts organized on these posts. I cannot promise though. If anyone has questions, ask away!
The Begining
Starting today, I am going to write about my game development adventures! Hopefully, crossing my fingers, that I keep up with this. I want to have a spot to discuss all of my failures and successes while I design my first ever game. I may not ever finish the game or make much progress on it; however, I do think it will be great to look back at my progress. This is my first post on my new blog and I will hopefully post later tonight to update everyone on where I am now.
If anyone is interested in what I am using for my development here is the list of tools:
Unity 4.0 Pro - Game Engine
C# - For scripts
Gimp - Open Source Photoshop
MonoDevelop - C# IDE
That is it for now! More to come!(hopefully) Dan
If anyone is interested in what I am using for my development here is the list of tools:
Unity 4.0 Pro - Game Engine
C# - For scripts
Gimp - Open Source Photoshop
MonoDevelop - C# IDE
That is it for now! More to come!(hopefully) Dan
Subscribe to:
Comments (Atom)



