Blog & Portfolio

Showing posts with label Coding. Show all posts
Showing posts with label Coding. Show all posts

20121109

Weapon Pickup Script (Javascript)


This script allows players to pickup weapons and assign them to their player. I have implemented a simple interface for the level designer so that when they place a generic WeaponPickup prefab down they can choose between all the available weapons which currently is 5. 

Within the script I hard code the weapon stats, to simplify the level designers GUI. Weapon statistics should be consistent within a game so there is no need for them to modify the stats of each weapon pickup they place in a level. One statistic the level designer can adjust is the respawn time of the weapon, this is a vital variable as it could effect the actual flow of a level if a weapon takes X time to respawn.

I have applied three statistics to each type of weapon, these include range, speed and damage. 

The script detects if the collider is first a player (as later in development abilities such as a banana skin collider could trigger the pickup and cause the game to glitch.) and then checks whether the player already has the weapon, if so the script returns and the pickup continues to be active.   

The only issue with the script currently is if a player picks up a a weapon, and then another player joins, the weapon pickup is visible to them (and they can pick it up) but it is invisible to all pre-existing players who were in the game when the weapon was picked up. The way to solve this (which I have done with the Access Key) is to photonView.RPC("FunctionName",PhotonTargets.AllBuffered) - This means, using the buffer, that when a new player joins the game they are sent a stream of what has happened and they enter up-to-date with the current game.  





Spawn Script (Javascript)

This script has caused me a lot of problems (trying to get it right). The original script setup meant that whenever a level was made, spawn points would have to be manually added to two arrays (GameManager (C#) and PlayerSpawn(JS). This proved tricky with having over ten respawns, which meant dragging 20 generic spawn points in to the arrays without knowing if I had brought the same one in twice and missed one out. 

I managed to get around this problem by making the spawnPoint prefab include a tag called "SpawnPoint", this would then allow me at the start of a game load up any spawnpoints within the level and automatically slot them in to an array with no fixed length. This means the script now works for a small four player map or a twenty player map.  

OnSignal is what the Player calls when they die, this then resets their variables and places them at one of the spawnpoints throughout the map. 

My problem now with this script, is that when a player respawns and a spawn point theres the chance another player may have instantaneously respawned at the same time in the same spot which causes issues (especially on the character select screen). I need to look in how to make the array globally update for all players, and when a random spawn is assigned it then is removed (RemoveAt) from the array for (WaitForSeconds(X)) seconds and then (Push(Y)) pushed back in. 




Initial Start-up

I have put myself forward as the coder for a game I am developing with fellow students at Futureworks, Manchester. The team in its current state comprises of myself, Alan (3D Modelling), Niall (3D Modelling), Sean (UV Texturing) and Josh (Level Design & GUI). The game originated from a paper based game concept we fleshed out over a series of weeks, and refined to the point where we could enjoy playing games spanning over three hours.

The game is a huge game of cat and mouse, where everyone is a cat and everyone is a mouse.

The environment is based within a prison block, using the prison features to make the gameplay more immersive and exciting. I have been developing a series of game mechanics within Unity using Unity Javascript and C# that the level designer can easily understand and implement in to his level concepts. 

Throughout this process I will be blogging development of the code I am implementing (and learning) to make the game come together.