Scripting – Lessons from the text
Much of the text was covering the basics of how to make a character, state, and camera controller. Much of the facts of this I was already aware of but it was great to get a nice clean and simple solution to all of these problems. Since this game uses unconventional controls not all of this will be useful to me but I will certainly reference this part of the text for future games that use more standard controls. One such thing was the Input manager which allows you to assign keys to certain input axis and makes scripting a whole lot more intuitive and quick.
The most useful thing about this section of the book was the description of the built in functions that control when code is executed. These include Update, LateUpdate, FixedUpdate, Awake, and Start. For example Update runs once each frame and therefore can be at an inconsistent rate. FixedUpdate uses the physics time-step that you can set and therefore runs at a fixed rate as the name would suggest. This makes it ideal for programming movement and things that you want to happen consistently.
Implementation Added Features
Since I’ve completed world 1 I have started on world 2 which has a cave theme. Previously I had assembled much of the needed assets and built a sample level but now I’m starting to code the actual puzzle functionality.
The first new feature is a new spell. If you cast it on yourself you will speed up for a set time. If you cast it as a projectile it will shoot a beam of lightning. This was difficult to implement. I found a public domain prefab of an awesome lightning bolt that could be set at a starting point and draw to the point of a transform set as a target. I used this to my advantage and made it act just like any other spell even though it’s fundamentally a line renderer rather than a rigidbody. I assigned the lightning prefab as a child of the wizard and turned it’s rendering off. I added an invisible rigidbody to the wizard’s spell array which is what actually get shot when you cast the spell. When you cast the spell the lightning bolt finds the projectile, Assigns it as its target and draws a line to it. When the target is destroyed the lightning turns rendering off again. This results in a very cool and unique looking spell while keeping the way spells interact with the world fundamentally the same.
Lightning Prefab found at Muse Games
For this object I had to work some of my limited artistic ability and draw it myself. It’s meant to be shot with the lightning bolt to activate some kind of machinery. Most of the time this will be some sort of door or platform animated with an iTween Event. I’ve coded it so that each box has a target with an iTween Event. When you hit the box with a lightning bolt it starts up some cool effects and then calls the play function on the targets animation. This is a very simple and flexible solution that will allow for a large variety of puzzles with no additional coding.
Again for this I had to draw it myself and I must say it turned out pretty decent. The boulder can supply two kinds of puzzles.
A: the boulder can kill the wizard if it hits him at a high enough speed.
B: the boulder can break certain walls
Sometimes the player will have to run away or dodge the boulder and other times they must use it to get past certain obstacles. I’ve also added some nice looking particle system effects for when the boulder destroys a wall.