Interactivity - Lesson No.3

In this lesson we were taught how to create boundaries for the ship so the player couldn't go off screen, put in a tilt as the ship moves from side to side, and create the shots that the ship will shoot.

Ship Boundary and Tilt


To begin with we added in boundaries scripting to our previous C# script that makes the ship move, all we needed to do was add a boundary public variable and edit how far the player can go. To choose the boundary limits you need to go into the inspector window and change the boundary values to whatever is appropriate for your game, for me it was:
  • xMin = -6
  • xMax = 6
  • zMin = -2
  • zMax = 8

Next was adding in the tilt option for the ship, which only took an extra two lines of coding.


All you needed to do was add in another public variable for tilt, and then add in another line of coding under FixedUpdate to control the tilt. The reason that it is -tilt at the end of the coding is because you need the ship to tilt the opposite way to how it's scripted. 
Then all thats left to do is change the tilt value for the ship in the inspector window, I changed mine to tilt = 4 because it seemed like a suitable amount. 

Creating Shots

To create a shot we first created a new GameObject and renamed it to 'bolt', and then reset the position it was in. We then created a new Quad by right clicking on the Hierarchy window and clicking 3D Object - Quad, renamed it VFX, reset the position and changed the rotation to x = 90, and then made it a child of Bolt. This was the base of the shot created, now we had to create a material for the quad.

To create a new material all you do is right click in the material folder and select Create - Material, and then rename it to something sensible. This is what you will get:


The next thing to do is to add a texture to the material, to do this click the header in the inspector window to reveal more options. From there it's pretty simple, all you need to do is click on select under the text square and choose a new texture which will appear on the material. There is even a preview window at the bottom which shows what the material will look like:


Next the material needs to be added to the quad, just click and drag it on top and it will appear however it will be a square with an orange line in it. To get rid of the black background change the shader on the quad by selecting particles - additive and this will give it more of a laser beam feel. 

The next thing to do is add on rigidbody to Bolt (the GameObject) and deselect gravity so that the bolts don't just fall straight through the game when it's played. 

Only one mesh is needed on either of these components (Bolt and VFX) so the best thing to do is delete the mesh collider from VFX, and then add on a capsule collider to Bolt (GameObject). The direction of the capsule collider needs to be changed to the z-axis and then adapt the radius and height to fit the bolt.



Unknown

Phasellus facilisis convallis metus, ut imperdiet augue auctor nec. Duis at velit id augue lobortis porta. Sed varius, enim accumsan aliquam tincidunt, tortor urna vulputate quam, eget finibus urna est in augue.

No comments:

Post a Comment