Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Third person shooter - Learning project

Discussion in 'Made With Unity' started by TwiiK, Mar 29, 2009.

  1. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,699
    Hi everyone.

    This is my first Unity project, about 20 hours in the making. :D

    Eventually (hopefully) it will be a multiplayer quake 3 style shooter with a game mode which lets you play cooperatively against waves of enemies.

    New version uploaded

    Click the title, image or here to try it out.

    It may be a bit resource hungry, I don't know because I'm getting about 1000fps on my beast machine. A more conservative system may struggle some as I set the settings to fantastic.

    I'm using just primitive geometry as well as assets from different tutorials because I don't want to spend time modeling and texturing when I could spend that time learning Unity.

    I thought I'd post my game here to get help, information and input from the community while I worked on it. And I think it's fun already so maybe you do as well. :wink:

    Controls
    Control character: WASD or directional keys
    Control camera: Mouse
    Control time: Scrollwheel
    Jump: Spacebar
    Shoot: Left Mousebutton or CTRL
    Different weapons: Numeric keys (1-6)
    Show cursor / pause game: ESC

    I've been a long time lurker here, but waited for 2.5 before actually going past just opening Unity. We have 1 or 2 copies of Unity Indie at work and even though we've never had the time to use them they are all bound to different macs so I'm using the trial version at the moment.

    I have nearly zero programming experience and when I started this project I had barely opened Unity before, yet I haven't gotten stuck a single time. If I wanted something in my game I have been able to create it or piece it together from snippets found on the web. It is just so beginner friendly. :)

    There is of course quite a bit of code taken from the different tutorials on this site, and many of the assets are from the same tutorials or commercial games and mods, but seeing as this is a learning project I didn't mind and I doubt anyone else will either. :)

    I have made quite a bit of maps and smaller mods for different Unreal games, Crysis and Half-life 1 and 2 and I feel the tools in Unity can easily rival those supplied with many of those games. And the Unity interface is one of the most intuitive and easy to learn I've encountered.

    Sorry for the ramble.

    Things I'm planning to implement into the game in the weeks to come:

    - Levels with enemies which progressively get harder (added)
    - More enemy types (added)
    - More weapon types (added)
    - Better AI
    - Maybe even some assets of my own :)
    - Textures
    - Multiplayer

    More to come. I will just overwrite the existing web player when I make changes, except if they are something very experimental.

    Edit: Updated the links to point to the latest version.

    Edit2: Updated some information to reflect changes in the latest update.

    Edit3: Fixed the broken links resulting from my server transfer and updated some information

    Edit3: Changed some information to reflect changes in latest update.

    Edit4: Edited the links to the game
     
  2. Charles Gill

    Charles Gill

    Joined:
    Aug 1, 2008
    Posts:
    142
    Great little prototype. A lot of fun.
     
  3. Thomas-Pasieka

    Thomas-Pasieka

    Moderator

    Joined:
    Sep 19, 2005
    Posts:
    2,121
    That's indeed pretty cool for a prototype! Would be even more fun as "multiplayer" :p

    Thomas
     
  4. VoxelBoy

    VoxelBoy

    Joined:
    Nov 7, 2008
    Posts:
    217
    Wow, nice work! Do post your regular updates. I'm watching this topic :)
     
  5. twitchfactor

    twitchfactor

    Joined:
    Mar 8, 2009
    Posts:
    352
    Very nice little prototype. I think you've got a handle on most of the problems, but I'll go ahead and let you know mine (it is the interweb afterall :wink: )

    1. Cursor's hard to read, especially at distance, making for many missed shots.

    2. The gun is on the side of the character, but expectation is that the weapon would fire towards the center of the character.

    3. Everything having the same texture means things get lost (walls, enemies, floor, etc).

    4. The camera seems pretty high for a 3rd person shooter. If it were a 3rd person brawler of adventure/platformer, I'd say it was ok, but too high for a shooter.

    5. Needs a HUD, so I know how much health I have.

    Like I said, really awesome prototype. I wish I had something as cool after 20 days, let alone 20 hours (my day job is unnecessarily demanding and unfortunately in the same field as my "hobby").

    I've played it on my laptop; Intel duo core 2.17ghz / 2gb ram :cry: / Some Intel integrated crap graphics card. I was getting ~24fps most of the time. I'm impressed it was that high considering you're using physics objects for the tracers versus a raycast and some grfx jiggery-pokery.

    You mentioned you had NO programming experience, but worked on mods. Do you have Kismet experience?


    Anyway, Great work! Keep us posted. I look forward to your next rev (also inspires me to get off my lazy ass and do something b4 my 30-day trial is up!)
     
  6. Sakar

    Sakar

    Joined:
    Feb 12, 2009
    Posts:
    141
    Haha, me too. Unfortunately I can't come up with any ideas, or at least, something I'm capable of.


    Great prototype TwiiK! Only thing I don't like is how hard is to aim, especially at those turrets. Keep it up and soon you'll have a pretty cool little game :)
     
  7. maxwelldoggums

    maxwelldoggums

    Joined:
    Sep 8, 2008
    Posts:
    157
    Very nice. Reminds me of the recent post...

    http://forum.unity3d.com/viewtopic.php?t=20074

    You don't need crazy graphics to make an epic game.

    I like it so far. It's fun to play, and relatively simple. You have the core gameplay very well done, that's a good thing to focus on too... (I learned that the hard way :D )

    A few things I recommend though... you should try to do an over-the-shoulder view for the player, much like many more modern 3rd person shooters, where the camera is positioned directly over the player's gun. This makes it much easier to aim, see the picture below if you don't understand what I'm rambling about.

    http://darkdiamond.net/wp-content/uploads/2008/05/resident-evil-5-art6.jpg
     
  8. minevr

    minevr

    Joined:
    Mar 4, 2008
    Posts:
    1,015
    Role is very cute :D
     
  9. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,699
    Thanks for the nice comments. :)

    I made a small update to the game which includes:

    - Plasma bolts now detonate on collision with an enemy
    - Laser Sight can be enabled/disabled with the "e" key on the keyboard
    - Proper HUD crosshair
    - Better aiming. The guns now aim towards a raycast hitpoint instead of just straight ahead.
    - Simple developer textures just to make it look a little nicer
    - New and bigger level layout

    That's about it.

    You can find it here or in my first post: http://www.twiik.net/sites/default/themes/twiikv2/twiikashoot_new.html

    Still experimenting with the camera and it's still quite buggy. I loaded up Gears of War after reading Maxwelldoggums's comment and tried out a similar camera viewpoint, but the pivot needs to be changed or something. I think I want the camear a little further away.

    Didn't have time to make some bigger changes, but I will try to squeeze in some time tomorrow.

    No, that's for UE3, right? I haven't had the chance to play with that and now that I have Unity I doubt I ever will. :)

    Btw, I think Unity seriously needs some better scene edit tools. Like grid snap, angle snap, vertex snap etc.

    The new level is grid based mainly just to keep things neat, but also in case I want to make a random level generator later on. And it was a little tiresome aligning things with no form for snapping.

    Edit: Fixed broken link
     
  10. Thomas-Pasieka

    Thomas-Pasieka

    Moderator

    Joined:
    Sep 19, 2005
    Posts:
    2,121
    Those "developer" textures look super familiar to me :p Nice update Twiik! Keep at it... I like what you're doing here.

    Thomas
     
  11. Dakta

    Dakta

    Joined:
    Apr 8, 2008
    Posts:
    492
    The new textures and aiming make it a bit easier.

    Just one problem: the 3rd person push bodies. I try to go up the box stairs, and I push them over, and can't get up. Then, I can't get the boxes back up, and I can't finish the game. :( Can you somehow make that less of an issue?? Please?


    Pretty awesome, anyways you say it, though.
     
  12. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,699
    There is nothing to finish at the moment. :)

    There may be a goal of some sort next update.

    I think I actually made my own pushbodies script because I didn't find the included one. I saw the thirdpersonpushbodies script yesterday, but forgot about it. I will check it out and tweak the one that works best in a future update.

    Hehe, Thomas, buying your tutorials has to have some advantages, right? :)

    I remember loving the developer textures in the Hammer editor for Half-life 2, but was unable to extract them. Then I remember you had some great ones as well so I put those in there. :wink:

    The level as it is now is just cubes in different sizes created in the editor. I may try to model a similar scene in 3ds max to try out lightmapping and some other things at the same time.
     
  13. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,699
    A very tiny update and quite a few problems. :)

    I've added bullet hole decals to the machine gun and changed the camera. Well, at least I spent quite a few hours trying to change the camera, but I'm struggling.

    Here's the latest version:
    http://www.twiik.net/sites/default/themes/twiikv2/twiikashoot_new.html

    I played some Gears of War, Ghost Recon, GTA 4 and Dead Space to look at their third person cameras and they all use more or less the same system:

    - The camera pivots around the character at shoulder height
    - The controls are exactly like a first person shooter
    - The weapons aim at a crosshair in the center of the screen

    I want a similar camera in my game and I feel I'm getting very close, but I'm facing a few issues.

    In the current build I'm using the OrbitCamera script I found in the third person tutorial on the main camera. The player himself is controlled by a first person controller and I attached a small script to the weapons which gives them the same rotation as the camera.

    Everything is great except the camera doesn't move with the player when he rotates. It just rotates around itself. So if you rotate 180 degrees the camera is on the player's left side instead of his right. It should have the same postion relative to the player all the time, but I'm unable to make that happen.

    Also, the weapons miss their mark.

    I've tried countless variations where the camera raycasts a ray, the player raycasts a ray, different camera scripts, variations where the weapons look at the ray hit, variations where the player looks at the ray hit etc. Written different camera scripts and googled my brains out, but I'm not not getting it as I want it. What I have now is probably as close as I've gotten.

    My problem with using a raycast is that when you aim at the sky it doesn't hit anything and thus the player won't aim higher than the highest wall which was last hit.

    Here's the blunt of the orbitcamera script:
    Code (csharp):
    1. function LateUpdate () {
    2.     if (target) {
    3.         x += Input.GetAxis("Mouse X") * xSpeed * 0.02;
    4.         y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02;
    5.        
    6.         y = ClampAngle(y, yMinLimit, yMaxLimit);
    7.                
    8.         var rotation = Quaternion.Euler(y, x, 0);
    9.         var targetPos = target.position + targetOffset;
    10.         var direction = rotation * -Vector3.forward;
    11.        
    12.         var targetDistance = AdjustLineOfSight(targetPos, direction);
    13.         currentDistance = Mathf.SmoothDamp(currentDistance, targetDistance, distanceVelocity, closerSnapLag * .3);
    14.        
    15.         transform.rotation = rotation;
    16.         transform.position = targetPos + direction * currentDistance;
    17.     }
    18. }
    currentDistanse is the offset value for how far away from it's pivot point the camera should be.

    The player is the target.

    The camera is parented to the player object and what I would guess should be in the code somwhere is transform.localPosition to ensure that the camera stays where it should relative to the player, but whenever I try putting localPosition in there it messed it up completely.

    I may just be tired and the solution may be obvious, but I'm asking this question so I may wake up to some helpful input in the morning. :wink:

    Anyone able to lend a helping hand? :)

    Edit: Fixed broken links and removed outdated dynamic shadows version
     
  14. gamingnotebook

    gamingnotebook

    Joined:
    Apr 1, 2009
    Posts:
    6
    the gun goes around in circles now with the new update and you don't know were your shooting. otherwise this project is create 8)
     
  15. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,699
    New update:

    - Added a HUD (finally managed to make it not crash my game at random :D)
    - Completely rewritten my way of handling ammo allowing me to have easily manageable pickups etc.
    - Added a new weapon: Guided missile launcher (very bugged, but kind of fun :)) Select it with "4"
    - Added 1 ammo pickup type for each weapon, and randomely scattered a bunch of them around the level
    - Changed the camera again and reverted the aiming to raycasting (introducing new bugs and issues and removing old ones)
    - Enemies can now drop fuelCells as well as health. The fuelCells don't do squat at the moment except reduce the Items counter in the lower right corner :) (I actually forgot to disable it before I built the game and I'm to lazy to reupload it) The fuelCells will be some kind of currency or similar in a later update.

    Try it out here:
    http://www.twiik.net/sites/default/themes/twiikv2/twiikashoot_new.html

    I didn't overwrite the old version of the game this time so if anyone wants to help me with my camera issues you can have a look at my last used camera system in my last post.

    As evident in both the player controls and especially the guided missile controls I'm really struggling with the game camera in Unity. :? I suspect it's the vectors and especially the quaternions that are confusing me. I've had to brush up on my vectors a few times already, but the quaternions I'm having a harder time with.

    Still no goal or purpose to the game, but maybe in the next update. :)
     
  16. CoatlGames

    CoatlGames

    Joined:
    Apr 25, 2008
    Posts:
    773
    very funny

    the plasma ball has the sound of the portal energy balls hehehehe :D

    nice work
     
  17. Thomas-Pasieka

    Thomas-Pasieka

    Moderator

    Joined:
    Sep 19, 2005
    Posts:
    2,121
    Very nice update Twikk. I like the missile...especially that you can "fly/target/navigate" it :D I am happy to see that you not only take the dev textures from my video training but you seem to model your levels according to what I teach (If I am not mistaken here). Correct me if I am wrong though :)

    Maybe we can do something together in the future (short little FPS perhaps?) ;)

    Thomas
     
  18. joshmorris3d

    joshmorris3d

    Joined:
    Jun 19, 2008
    Posts:
    151
    Well done, It is fun!

    Once the enemies see me they block me into a corner and I can't move so I just sit there and die. Maybe you can make the enemies stop at a reasonable distance and start firing so the player has a chance to escape.

    I'll be looking for the updates to this.

    Cheers,

    Josh
     
  19. maxwelldoggums

    maxwelldoggums

    Joined:
    Sep 8, 2008
    Posts:
    157
    How did you create the bullet holes? are they decals?
     
  20. Dakta

    Dakta

    Joined:
    Apr 8, 2008
    Posts:
    492
    Yep, I believe so!

    Probably could get some ideas for the required code from the splatter demo... It's here in the forum somewhere.
     
  21. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,699
    I'm not actually sure what the technical term decal implies, but they are planes with a texture applied. :)

    I then instantiate the planes wherever the raycast hits and position them according to the normal of the surface hit.

    The shaders included with Unity gave me flickering when I positioned a plane on top of my geometry and offseting the bullet hole from the geometry looked wrong. Then I discovered the BlendedDecal shader in the wiki which worked perfectly without having to offset the bullet holes from the geometry.
     
  22. cry0

    cry0

    Joined:
    Apr 9, 2009
    Posts:
    71
    Hi everyone,

    First, let me congratulete you TwiiK on the nice work.

    I would like to ask you, since I can't find the reference to it, how do you maintain the mouse locked "inside" the web player? I'm referring to the whole "click to start playing/press Esc to free mouse" thing.

    In my test app I need to click on objects for triggering events, and since in the web player the mouse is going outside the web player's boundaries this sometimes poses problems.

    Thank you
     
  23. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,699
  24. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,699
    New update:

    - New enemy type. Taken from the FPS tutorial and tweaked a bit to allow for aiming in the vertical direction and improved the animations a bit.
    - New weapon - Grenade Launcher. Grenades within the explosion radius of other grenades will detonate eachother. Kind of bugged because the grenades check for colliders within the radius and I'm not sure how to exclude the grenade doing the check, so now 2 or more grenades can end up creating 5-20 explosions by detonating eachother multiple times.
    - Artilery Strike ability, selectable with 6. Hold the fire button and artilery will rain from the sky. For fun I've made it so you can call one artilery strike every second by just holding the button down. Will cause massive destruction and probably system failure. :)
    - Improved controls. Still not perfect, but better.
    - Added scoring system. Enemies add points to your score when killed.
    - Removed Lasersight. It now acts as the targeting laser for the artilery strike instead.
    - Changed the lighting. I had 2 directional lights, 1 for the sky and 1 for the sun. I now deleted the skylight and adjusted the ambient light. It doesn't look as good, but runs a lot faster.
    - Improved physics. Mainly by adjusting weights, gravity and physics materials.

    There may be more changes since the last version, but I forgot to check the old web player before I updated it. If something has changed I'm sure you'll notice. :)

    http://www.twiik.net/sites/default/themes/twiikv2/twiikashoot_new.html (7mb)

    Sadly still no goal or purpose. I will look into that in the next update. I'm thinking of a wave type survival thing which I think will be not to difficult to implement, but a lot of fun.

    Edit: Fixed broken links
     
  25. Bugfoot

    Bugfoot

    Joined:
    Jan 9, 2009
    Posts:
    533
    Great work Twiik! You have a lot of features in already. I like the guided missile (even though the controls were a bit odd). I did something similar for a Quake2 mod and it was lots of fun in multiplayer :)
     
  26. Sakar

    Sakar

    Joined:
    Feb 12, 2009
    Posts:
    141
    Wow! Love all the new features. Really fun to play.
     
  27. Thomas-Pasieka

    Thomas-Pasieka

    Moderator

    Joined:
    Sep 19, 2005
    Posts:
    2,121
    It's coming along nicely Twikk! Love the additions. Keep it coming man!


    Thomas
     
  28. designerwatts

    designerwatts

    Joined:
    Apr 2, 2009
    Posts:
    18
    A very nice demo so far. :) Having done 2 years of level design in the Wii console market I'll give ya a few pointers.

    1. Make sure that everywhere can be accessed regardless of environment change. What that means in your demo is that movable physics boxes are used as a climbing tool to get to new places. This is fine but you should always allow at least one solid geometry based clear way to get up and access everywhere. At the moment if I move the boxes around I Can't gain access to these areas.

    2. Have a goal. The goal of the map isn't clearly displayed to me and I have no idea how to progress. Perhaps you can have a tally of remaining enemies on the map and when it reaches zero a portal opens up to take you out of the level..something like that.

    3. Tweak the weapons.
    - The guided missile is really hard to navigate. If you could implement standard FPS mouse look controls when guiding a missile it would be tons more fun to use.
    - Artillery. I'd really rather have 1 ammo of artillery just make for one bombardment that's placed exactly or very close to the target I was pointing at with my laser. Having it shoot 3-5 bombardments that don't hit he target doesn't make it an effective weapon. Also it's quite powerful so giving the player 100 of them is a bit much. :)


    This demo is great though. And I'm looking forward to seeing it further evolve and develop.

    Cheers,
    Chris Watts
     
  29. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,699
    Thanks for the comments.

    designerwatts, I agree with everything although I stated there isn't any goal or purpose to the game as of now and that I intentionally unbalanced the artilery for fun. :)

    The map design is just lazyness. I just add what I feel like and think no more about it. Most of the game is just temporary anyway.

    The next update won't have a goal you need to reach, but it may have a purpose - To stay alive as long as possible. :wink:

    The guided missile is a result of my continuous struggle with the quaternions. :) Every time I instance something or add a mouse control or a camera I get a different result from the last. Just making a rocket fly straight out of the barrel of a gun is a hassle.

    For example I copied the rocket launcher script from the player and put it on the AI humanoids and suddenly it shoots straight up instead of straight ahead. And when I tried rotating it the rockets came out sideways. It's not supposed to be easy. :)
     
  30. BmEcko21

    BmEcko21

    Joined:
    Oct 4, 2008
    Posts:
    7
    The artillery is pretty cool.
     
  31. cry0

    cry0

    Joined:
    Apr 9, 2009
    Posts:
    71
  32. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,699
    http://www.twiik.net/sites/default/themes/twiikv2/twiikashoot_new.html

    Major update (biggest so far):
    - Whole project converted to C# (About 60 scripts in total)
    - New weapon - Pistol
    - New weapon - Shotgun
    - Removed weapon - Guided missile launcher (didn't suit the twitch gameplay I'm aiming for, and it was bugged)
    - Optimized a lot of particle effects
    - New wave system (thanks to Spk from the PainTrain thread)
    - Optimized enemy code a ton allowing me 5-6 times more enemies at once (there's about 150 enemies at once in the final wave)
    - Respawning ammo scattered around the map
    - Enemies now drop random ammo as well as health (dissapears after 30 seconds so be quick)
    - Enemies now jump/climb (akwardly and quite amusingly :)) when they are near walls so no place is safe
    - Pistol, Shotgun and Machinegun has gotten improved bullet code (again based on Spk's code)
    - Coded in inaccuarcy for Pistol and Machinegun. The longer you hold the trigger (or the faster you hit the trigger in the pistol's case) the more inaccurate they will get.
    - Removed lives. If you lose all your health the game resets, abruptly and without warning. :)

    A few notes:
    - There's 7 waves in total. The first 6 are the proper waves, the last one is a bit wacky. :)
    - The final wave has about 500 enemies total and a ton of them at once. I don't expect your computer to be able to handle this, it was just to test how many I could handle. My system goes below 50fps in the final wave and the game beings to stutter, but it stays well above 100fps for the first 6 waves.
    - Enemies may get stuck in a few spots on the map so if there's no enemies and you don't get to the next wave take a look around.
    - You start without ammo for the more powerful weapons. It is scattered around the map and it drops from enemies.

    Plans for the near future:
    - Use points/money to buy weapons and maybe ammo
    - Some menus including start game, game over etc.
    - Maybe improve the ingame hud
    - Different enemy types

    Plans for the distant future:
    - Bosses
    - Stats and upgrades for weapons and your character
    - Multipliers, powerups etc.
    - Artwork
    - Pathfinding for enemies so instead of flying up tall walls they go around to find the shorter walls or ramps.
    - bugfixing balancing

    Known bugs:
    - If you let the pistol run out completely of ammo and later find ammo it won't reload. (I will rework the code and allow for pressing a reload button to reload as well)
    - The grenade launcher is weird. Mainly due to the physics. No matter what I tried with gravity, physics materials and mass the grenades just bounce too funky.
    - Enemies may get stuck while "climbing" the tallest walls. I think it's because the ray I use to check with perfectly goes between the two colliders making up the wall and therefore doesn't register a wall in front of the enemy.

    Would be nice if you could tell me your observations and suggestions, about bugs you find, or how the game performs for you. Include your computer specs for the latter so I know how the game perform on other systems. :)

    Cheers.
     
  33. VoxelBoy

    VoxelBoy

    Joined:
    Nov 7, 2008
    Posts:
    217
    Wow, this update is the best thus far. All issues I encountered in the previous versions seem to be fixed and the game is actually a lot of fun :D Amazing work. I really like the texture on the enemies, both alive and dead. The most fun part was shooting a bunch of them with rockets or artillery and see them fly away. Keep it up buddy!
     
  34. Dakta

    Dakta

    Joined:
    Apr 8, 2008
    Posts:
    492
    It would be nice to know how many boxes we have to collect to activate the better weapons.

    Other than that, looks awesome!
     
  35. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,699
    All weapons are activated from the beginning. They're selectable with the number keys ( 1 - 8 ). You just don't have ammo for them. When you find ammo for them just press the corresponding key to equip the weapon.

    In the next update the hud will, hopefully, make it clear which weapon you have selected and you will have to buy new weapons with the points you earn.
     
  36. angel38

    angel38

    Joined:
    Apr 13, 2009
    Posts:
    100
    Oh, very nice you project man.

    If you keep the simplicity, that game will be a Hit.

    Congratulations.
     
  37. MentalFish

    MentalFish

    Joined:
    Nov 2, 2005
    Posts:
    282
    Love the baddies and the simplistic style of it all! Keeping an eye on this.
     
  38. Lab013

    Lab013

    Joined:
    Oct 22, 2008
    Posts:
    405
    Nice! Wave5-6 lag me up and make it so I can't move though. Great game though, has potential.
     
  39. Discord

    Discord

    Joined:
    Mar 19, 2009
    Posts:
    1,002
    Very fun! I was doing alright until I got to that last level. I was dead before I knew it. :roll:
     
  40. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,699
    Thanks for all the comments. :)

    The lag making you unable to move I'm aware of. I've had that happen a few times.

    A ton of people have been sending me PM's with a myriad of different questions about the game. I would prefer that people ask here in the thread so everyone can see the Q&A's, but I will post some stuff here as answers to some of the questions.

    How did you do the ammo handling (ammo pickups, ammo count)?


    The ammo handling is done in 4 different scripts:
    - MachineGun.cs which is attached to the MachineGun game object and subtracts ammo when the MachineGun fires.
    - PlayerStatus.cs which is attached to the Player and tracks ammo among other things. This script contain all the functions which deal with the ammo count.
    - PickupAmmo.cs which is attached to the ammo pickups and adds a set amount of ammo when the player picks up a pickup.
    - AmmoSpawn.cs which spawns ammo pickups at set intervals for the player.

    MachineGun.cs
    - This is the script that's attached to the MachineGun Game Object.
    - If the user hits the fire button the Fire() function is called.
    - Fire() calls ReturnAmmo in PlayerStatus with "MachineGun" as an argument to get the remaining ammo in return. I'm using a switch every weapon has its own case.
    - If there's ammo left FireOneShot() is called which subtracts one round through the SubtractAmmo() function.
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class MachineGun : MonoBehaviour {
    5.  
    6.     public float fireRate = 0.1f;
    7.  
    8.     private float nextFireTime = 0.0f;
    9.     private PlayerStatus playerInfo;
    10.     private float triggerTime = 0.1f;
    11.  
    12.     void Awake() {
    13.         playerInfo = (PlayerStatus)FindObjectOfType(typeof(PlayerStatus));
    14.     }
    15.  
    16.     void Update(){
    17.         if (Input.GetButton("Fire1"))
    18.             Fire();
    19.     }
    20.  
    21.     void Fire () {
    22.         int bulletsLeft = playerInfo.ReturnAmmo("MachineGun");
    23.        
    24.         if (bulletsLeft == 0)
    25.             return;
    26.  
    27.         if (Time.time - fireRate > nextFireTime)
    28.             nextFireTime = Time.time - Time.deltaTime;
    29.            
    30.         while( nextFireTime < Time.time  bulletsLeft != 0) {
    31.             FireOneShot();
    32.             nextFireTime += fireRate;
    33.         }
    34.     }
    35.  
    36.     void FireOneShot () {
    37.         playerInfo.SubtractAmmo("MachineGun");
    38.     }
    39. }
    PlayerStatus.cs
    - Here's where ammo is handled.
    - We know what the ReturnAmmo() and SubtractAmmo() functions does and the AddAmmo() will be explained further down
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PlayerStatus : MonoBehaviour {
    5.  
    6.     public int ammoMachineGun = 100;
    7.  
    8.     public int ReturnAmmo (string ammoType) {
    9.         int returnValue = 0;
    10.         switch (ammoType) {
    11.             case "MachineGun":
    12.                 returnValue = ammoMachineGun;
    13.                 break;
    14.         }
    15.         return returnValue;
    16.     }
    17.  
    18.     public void SubtractAmmo (string ammoType) {
    19.         switch (ammoType) {
    20.             case "MachineGun":
    21.                 ammoMachineGun--;
    22.                 break;
    23.         }
    24.     }
    25.  
    26.     public void AddAmmo (string ammoType, int powerUp) {
    27.         switch (ammoType) {
    28.             case "MachineGun":
    29.                 ammoMachineGun += powerUp;
    30.                 break;
    31.         }
    32.     }
    33. }
    PickupAmmo.cs
    - This is the script that's attached to the pickups themselves
    - I declare a list of ammo types to allow me to choose them from a list in the editor interface
    - When the player enters the collider attached to the pickup the ApplyPickup() function is called, this function calls the AddAmmo() function in the PlayerStatus script with the weapon type and amount as arguments.
    - You may notice the functions, variables and checks related to spawning. They are there because the pickup can both be dropped by dead enemies as well as be spawned by ammo spawners.
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PickupAmmo : MonoBehaviour {
    5.  
    6.     public enum PickupType {Machinegun}
    7.     public PickupType pickupType = PickupType.Machinegun;
    8.     public int amount = 30;
    9.  
    10.     private bool used = false;
    11.     private DroppableMover mover;
    12.     private bool fromSpawn = false;
    13.     private AmmoSpawn spawner;
    14.  
    15.     void OnSpawn (AmmoSpawn spawner) {
    16.         this.spawner = spawner;
    17.         fromSpawn = true;
    18.     }
    19.  
    20.     bool ApplyPickup (PlayerStatus playerStatus) {
    21.         switch (pickupType) {
    22.             case PickupType.Machinegun:
    23.                 playerStatus.AddAmmo("MachineGun", amount);
    24.                 break;
    25.         }
    26.         return true;
    27.     }
    28.  
    29.     void OnTriggerEnter (Collider col) {
    30.         if(mover  mover.enabled) return;
    31.         PlayerStatus playerStatus = (PlayerStatus)col.GetComponent(typeof(PlayerStatus));
    32.  
    33.         if (used || playerStatus == null)
    34.             return;
    35.        
    36.         if (!ApplyPickup (playerStatus))
    37.             return;
    38.  
    39.         used = true;
    40.  
    41.         if(fromSpawn)
    42.             spawner.AmmoTaken();
    43.  
    44.         Destroy(gameObject);
    45.     }
    46. }
    AmmoSpawn.cs
    - This is the ammo spawner I mentioned above, it's attached to an ammo spawner game object which can be placed in your level and will spawn ammo pickups when the player picks them up
    - It instantiates an ammo pickup of the set type and when that ammo pickup is taken by the player it fires the AmmoTaken() function which in turn fires the NewAmmo() function which spawns a new pickup after a set delay
    - The ammo spawner also tells the spawned pickup that it came from a spawner. This is so the pickup knows to just appear and not bounce out as it would if it was dropped by a dead enemy
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class AmmoSpawn : MonoBehaviour {
    5.  
    6.     public enum PickupType {Machinegun}
    7.     public PickupType pickupType = PickupType.Machinegun;
    8.     public DroppableMover[] spawnableAmmo;
    9.     public string gizmoName;
    10.     public float respawntime = 30.0f;
    11.  
    12.     private DroppableMover ammo;
    13.     private bool fromSpawn = true;
    14.     private bool spawned = false;
    15.  
    16.     void Start () {
    17.         switch (pickupType) {
    18.             case PickupType.Machinegun:
    19.                 ammo = spawnableAmmo[0];
    20.                 break;
    21.         }
    22.     }
    23.  
    24.     void Update () {
    25.         if(!spawned) {
    26.             DroppableMover spawn = Instantiate(ammo, transform.position, transform.rotation) as DroppableMover;
    27.             spawn.SendMessage("OnSpawn", this);
    28.             spawned = true;
    29.         }
    30.     }
    31.  
    32.     public void AmmoTaken(){
    33.         StartCoroutine(NewAmmo());
    34.     }
    35.  
    36.     IEnumerator NewAmmo(){
    37.         yield return new WaitForSeconds(respawntime);
    38.         spawned = false;
    39.     }
    40.  
    41.     void OnDrawGizmos () {
    42.         Gizmos.color = new Color(1, 1, 1, 1);
    43.         Gizmos.DrawIcon(transform.position, gizmoName + ".psd");   
    44.     }
    45. }

    How did you make the bullet holes?


    Bullet.cs
    - When the bullets hits something it checks if the object hit has the tag = "Geometry" it will instantiate a bullet hole with the proper rotation
    - I just tagged all my static geometry and objects with Geometry to avoid spawning bullet holes on something movable.
    - The bullet hole itself is just a single polygon with a bullet hole texture applied
    - A crucial detail for this effect was the BlendedDecal.shader (http://www.unifycommunity.com/wiki/index.php?title=BlendedDecal) from Neil Carter. It allowed me to spawn the bullet holes on the surface of my geometry without them flickering
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Bullet : MonoBehaviour {
    5.  
    6.     public GameObject bulletHole;
    7.  
    8.     protected virtual void OnHit( RaycastHit hit ) {
    9.         Quaternion rotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
    10.  
    11.         if (hit.transform.tag == "Geometry") {
    12.             GameObject instantiatedBulletHole = Instantiate(bulletHole, hit.point, rotation) as GameObject;
    13.         }
    14.     }
    15. }

    How did you make the tracers?


    The tracer is just a trail renderer component added to the bullet game object with these settings:


    The tracer texture I use is attached as a file attachment. You can easily change the color with a tint in your material.

    Lastly I will just say that probably 90% of my project I've gathered from various tutorials and code examples posted by people here on the forum and in the wiki. So if you're a noob (like me) just spend some time searching and googling and you'll find what you need. :)

    I'm also not a very good programmer and a lot of my code is probably very convoluted, but it serves its purpose. It also gets constantly improved and rewritten as a gain experience both as a programmer and in the C# language.

    Btw, I think I have all the above code available in javascript because I recently switched to C# so if you really don't understand C# at all just ask for the examples in javasacript.

    I haven't had time to play with Unity or this project in nearly two months and hope to have some spare time this weekend.

    PS: These code examples looks incomplete and that's because I've removed hundreds of lines of code unrelated to the questions asked. They don't contain any errors afaik so they may work if you just copy them into your project for all I know, but most likely they will require some tweaks and are meant as examples.
     

    Attached Files:

  41. raiden

    raiden

    Joined:
    Feb 8, 2009
    Posts:
    327
    Thank you for sharing this game and all the information above! I have played your game, and you have done a wonderful job on it. My girls love to play it as well.

    The effects were great, the only thing I found which wasn't really a bad thing, when you jump to the higher areas, and shoot an enemy, if it turns in to a heart and an another enemy is behind the heart, the heart collider blocks it from moving, and your weapon fire will also be blocked by the collider when shooting the enemy with the heart in front of it.

    Still fun to play!

    -Raiden
     
  42. bobber205

    bobber205

    Joined:
    May 12, 2009
    Posts:
    139
    Is your webserver particularly slow tonight? I had alot of trouble getting the game to load.

    Of course it could be on my end as well.
     
  43. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,699
    I know of the pickup colliders blocking the shots. :) I will look at that as well as a ton of other things when I have the time.

    The server probably does its backuping and stuff at night (here in Norway) because that's when the load is smallest, this surely falls on completely different times of the day for some of you. :)

    The server itself is also more or less filled to the brim with heavy sites so I should probably move my little project to one of our newer server with less traffic.

    It should also be cool to finally complete my new site enough to make i available to people and then hook it up to google analytics to see just how many play my little game. :)
     
  44. Armagon

    Armagon

    Joined:
    May 29, 2009
    Posts:
    246
    Hello TwiiK, and thank you for this awesome post. I'm sure this will clear a lot of my questions. By the way, since you said earlier, can you post the JS versions of such scripts?
     
  45. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,699
    Here's a zip containing the JS versions of the above scripts.
     

    Attached Files:

  46. rawrman2381238

    rawrman2381238

    Joined:
    Jan 28, 2008
    Posts:
    122
    how did you do the laser for the artillery?
     
  47. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,699
    It's a line renderer with the texture I posted earlier tinted red.

    I raycast from the gun and the end point for the line renderer is the raycast hitpoint. The start point is of course the gun itself.
     
  48. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,699
    I've had some time to work on my project, but instead of spending it in Unity I decided to try and make some models for my game. Being a gun nut those models would of course have to be guns. :)

    First time I've opened 3ds max in 2009 actually.

    I began with a gun I've wanted to model for a long time, the Accuracy International AS 50 sniper rifle:


    But after a few hours I got a little bored and found I had at one time gathered references for a Colt Python revolver, but never started the actual model so I started that as well:


    So managed to squeeze in some quality hours of modeling today, had nearly forgotten how fun it is. I have to finish 1 of those weapons soon and try my luck at texturing and animation so I can put it into the game.

    The plan is to model the weapons using subdivision modeling techniques and then make some normal maps out of the high poly versions. Haven't tried that before so it should be fun.

    I've also decided to take the project to first person instead of third person because I realize it will take me years to learn how to model and animate a decent third person character so I'll just take that out of the equation and focus on the fun stuff like weapons and stuff. :)

    More to come at a later date.
     
  49. Thomas-Pasieka

    Thomas-Pasieka

    Moderator

    Joined:
    Sep 19, 2005
    Posts:
    2,121
    Nice modeling Twiik :) Did you get my PM by chance?

    Thomas
     
  50. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,699
    I did. :)

    I replied to it and I replied to your question on theunityartist.
     
unityunity