Shooting Unity 3D

Coding is one of my favored classes in NextGen I enjoy making things work and trying to make it more efficient and simplify it. I have been working on a 2D game where you can shoot enemies as this is part of my assessment which is very near. I decided it would be interesting to find out differences between shooting an object in 2D and 3D. I loaded up unity and made a camera and a base platform.

code ball forward.PNG

Currently the camera does not move  but it is still my player. I then made a prefabs folder and a scripts folder. I then made the sphere in my scene and added a rigidbody on it then I put it into my prefabs folder so it would retain the properties I put on it.

Currently the ball spawns upwards and balances on top of each other I am working on fixing this. The code spawns the balls with a velocity.

Concept Drawings

I have decided to try and make and archery game, so I drew up a list of some assets I may need to make and use though the game. The assets were quick sketches not really high detail but enough for you to be able to see what it is.

concepts.jpg

Obviously you will only really need the bow and arrow, but I felt it would look cool if there were other weapons on a table or being presented or perhaps scattered around the environment to secure the time period which would be medieval.

There is a viking helmet, Syth, sword, shield and battle axe.

grass in unity.PNG

For the game there will basically be a shooting range where the character will be shooting the arrows down a firing range and hitting a moving target. The targets will disappear after a period of time and re appear shortly after. I plan on adding a UI so you can keep track of score. The firing range will be a field so I have researched how to add grass to unity, the grass is a 2D texture which is just made in layer. i could have it slightly 3D If I were to use Maya’s grass. Too make the game a little bit more eye pleasing I will add terrain surrounding it so it looks like you are in a ditch to stop you seeing over a completely flat plane.

Enemy movement

For my assessment prep I have been working on the 2D Top down game, previously I have been stuck with the enemies that stare at my player though the walls. this was an issue as I was instantly dying as soon as I left the cover due to the rain of bullets upon me. I have been sifting though lines of code and I have found a way of making the enemy follow his waypoint path and only shoot on these axis. This is much better and looks cleaner as even though walls the enemy was always looking at my character.

enemy move waypoint gif.gif

I removed the ‘Trig2 Rotation’ script as this was what was controlling it and added these 3 lines of code which when broken down make the enemy focus/ aim towards his next way point. This is more eye pleasing and simple put its a lot better.

code new.PNG

Game Progress

For Ant and our assessment we needed to make a top down game, for this I have 2 enemies and one player. I added the movement script to the player allowing me to control him moving him with the WASD Keys. I then set the way points for the enemy to travel to. I realized there was no exit to the map so I added a portal and then added an auto rotating script to it to make it look better.

aaaa Bullet kill gif.gif

The bullets the enemy shot were going through the walls, this was bad as they would go through the walls and kill me as the enemies are always looking in my direction. I then added an OnCollision feature which meant when it collided with things it ended the game, the only thing was when the bullets hit the wall it ended the game. I then made it so when the bullets hit the player it then ends the game, I also made them collide with the walls so the bullets did not go through the walls.

I need to change the characters to the ones with the guns but I feel the code is more important at the minute due to the upcoming exam.

 

Space Game

For this game I had done quite a lot of work, there was initially a start screen when you open the game. After you press on the play button it would then load the next level I had used the UI System in order to achieve this. I had added code which detected the mouse click by using ‘on mouse down’

A few things had went wrong at first I had found it difficult to navigate the scene management making it possible to change levels. As you have to use the builder menu to load in each scene after I had wrote the code to change the scene I then had to change it on the next scene to then take me to the second level.

Space game GIF.gif

I had made the meteors go into an elliptical path which was because this is how it occurs in real life, I also added a rotate script cause meteors rotate as they move through space. On the first level I had used the stock images and attacked the camera to the ship. Which had a polygon collider assigned to it as I could adjust it to actually be the shape of the ship. Unity done a good job at doing it automatically so I didn’t even need to change anything. The stock images looked quite poor so the second level I had used my own space themed images I had gathered.

As the camera is attached to the ship it means as you spawn you can see the outside of the map and it looks poor so on the second level I had added a Sci- Fi background to it to make it look little bit more eye pleasing. I also added a collider around it so you could not exit the play region.

I added a timer to the maps as well so if you were finding it too easy it added that little bit ore pressure. After the timer hit 0 the level forces a restart. I had made the timer by using GUI Which I was surprised it still worked as this is old unity. I also added a death script to the meteors so once you collide with them it also forces a restart.

Waypoints for Enemies

I decided to add a more complex movement path for another enemy, this was to make the level seem more difficult by having more then one enemy to kill. The aim it to kill one while the other is not looking. The enemy goes out the room and then goes into the cupboard this is supposed to be the time to kill the other enemy the aim is to time it perfectly so once the enemy goes into the cupboard the other enemy will be near the entrance allowing u to discretely kill him.

enemy move gif.gif

After you kill the first enemy you will then be able to continue by killing the second one. I plan on adding obstacles to make it easier to kill the second enemy silently without being seen. Currently you do not die and you are not able to kill the enemy but I plan on adding this soon.

Top Down Updates

For my top down game there were a few errors which were rather unsatisfying to see such as the fact the character shoots bullets from a knife this was as I had intended the character to knife people to kill them but I have decided to change this to a gun, I may in the future make changeable weapons in a UI So players can choose how they want to challenge the enemies ultimately adding to the experience.

perf chacater coloured gun.png

For the character I literally added a gun, the arms are still in the same position. This made the character on a side on stance this is quite accurate how a trained individual fires a gun as they tend to stand sideways rather then face on. It turns out that the arm locations suited this quite well. I then coloured the gun into the typical AK style with the wooden grips and stock.

After I had done this I rotated the character until the gun was horizontal facing right. This is because this is the way unity load in things when it comes to adding movement to the character it makes my job a lot easier as I do not need to compensate for the angle being off when adding the x, y axis in the movement scripts.

Ball task

ball changing colour.gif

For this we were left to our own devices with the internet to hand. This opened an endless amount of possibilities for what we could come up with. We were told to make a ball and add some code to it which would make it do something. I stumbled across some code which involved using Nav Meshes. This enabled me to make the ball randomly move to locations within a set radius.

auto move.PNG

I made public variables so I was able to change then using the unity editor, this was just a to make it more convenient as it made it easier to edit things such as movement speed and the interval time for it relocating. I then had to add a ground plain then bake it to allow the nav mesh to function.

 

After I had it moving automatically I then wanted to add a little more so I added some code to make it automatically cycle through colours this however was not good enough as it only went though colours I had set and this was a lengthy process so I then adapted this code to automatically choose colours from the colour picker.

click colour.PNG

This is the code to change colours of the ball then you click the ball. It uses the ‘on mouse down function’

I also made an automatic scaling function to make the sphere pulsate so it grew and shrank automatically and in a sequence. The rate of the pulsating also corresponds with the changing of colour which I thought was really good.

 

 

Moving Enemy

Today, I wanted to make the enemy move as It seemed rather dull due to the lack of movement in my game. So I added a waypoints script. After I done this all I needed to do was set the points of which I wanted my enemy to move. I have made my enemy move backwards and forwards in a path. This is the first enemy, I intend to add a few more to add more off a challenge to the game.

Enemy attacking player.gif

At first the enemy moved backwards and forwards without any rotation at all. This was bad so I added a trigonometry script to make the enemy track the player. After I was content with the movement I then added an auto firing script. (Yes there is room for improvement, I want to add a vision script so he does not look at my player through the walls) There was also an issue with this as the bullets went though the walls which was not good. this lead me to adding a box collider and increasing the power so the bullet disappear on impact as it now collides with the wall.

bad enemy movement.gif

This is what the enemy movement was like when it was broken before I added the trigonometry scripts.

Due to the fact the bullet and the enemy has a collider they collide with each other. I made a new layer and called it enemy, I called this enemy. I then went into edit/project settings/2D Physics. This allowed me to edit the physics. I went to the ‘Layer collision matrix’ and went to the enemy layer. and un ticked this box so they no longer collide leading to smoother bullet firing.

matrix.PNG

For the enemy I just loaded my character into PS, then I copied it and changed the hue to make it red. This was because I wanted a variation between the character and enemy. I made him red because red is often associated with a baddie/ enemy.

Game Progress

I had found issues with my game which then lead to me to have to redo everything there was many errors with the scene as it loaded in as a 3D scene when I reloaded it so I had to lose this make a new 2D Scene and re-do my work

carpet.png

After I had done this I began making a number of standard assets which were to help create a scene. I made walls in Photoshop and I had made a carpet/ floor design to create a variation from the walls and the floor. The walls were in a Binding of Isaac style which I really likes.

GIF.gif

After I had developed the scene I then worked on fixing the code as the movement script was broken it turns out I had a minus in my code where it was not needed.