Search Unity

[RELEASED] Coop Action Game Kit - With Procedural Level Generation & up to 4p Local Coop

Discussion in 'Assets and Asset Store' started by DanielSnd, Jul 29, 2014.

  1. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,697
    I experimented with invisible walls (generating a collider mesh over the camera frustum) but ultimately decided against it in case a player somehow ends up outside the walls. Physics wouldn't allow the player to get back inside, so he would forever be trapped outside the camera view.

    Instead, I just zero out PlayerInput's v and h values if the player is at the edge of the view and is trying to move further out. In case anyone else wants to do this, here are the changes:

    In CamManager.cs, add this to the bottom:
    Code (csharp):
    1.     public Vector3 GetCenterPoint() {
    2.         return (Players.Count>1) ? midCenter : LookVector;
    3.     }
    4.  
    5.     private Vector3 GetEdgePoint() {
    6.         return transform.position + (Quaternion.AngleAxis(-camera.fieldOfView / 2f, Vector3.forward) * (GetCenterPoint() - transform.position));
    7.     }
    8.  
    9.     public float GetDistanceToEdge() {
    10.         return Vector3.Distance(GetCenterPoint(), GetEdgePoint());
    11.     }
    In PlayerInput.cs, in the GetInput() method, insert this just above "cM.TryMovement(h,v,LookWhereMove());":
    Code (csharp):
    1.         Vector3 center = CamManager.instance.GetCenterPoint();
    2.         float distanceToEdge = CamManager.instance.GetDistanceToEdge();
    3.         float distanceX = transform.position.x - center.x;
    4.         float distanceZ = transform.position.z - center.z;
    5.         if (distanceX > distanceToEdge && h > 0) h = 0;
    6.         if (distanceX < -distanceToEdge && h < 0) h = 0;
    7.         if (distanceZ > distanceToEdge && v > 0) v = 0;
    8.         if (distanceZ < -distanceToEdge && v < 0) v = 0;


    Best of luck on your move!
     
    DanielSnd likes this.
  2. DanielSnd

    DanielSnd

    Joined:
    Sep 4, 2013
    Posts:
    382
    That is incredibly awesome! :D Thanks a lot for sharing!

    The trip itself went great, I'm already at the new country ^^ I just don't quite have a house yet hahahah, shall be moving into the new place tomorrow :D
     
  3. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,697
    I've updated the code since. I'll PM you the script files. Thanks for developing this fun kit!
     
    DanielSnd likes this.
  4. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,697
    Several people have asked about getting Shooter AI working with Daniel's COOP Action Game Kit. I only did a simple proof of concept just as an excuse to dig into the kit's scripts and see some more advanced behavior. I eventually went with a different AI solution, but here are the steps I used to quickly see Shooter AI work in the kit:

    1. Added Shooter AI's SoldierPrefab to the scene.

    2. Set the root object layer to Enemy.

    3. Added a CharacterController, characterHealth, characterMove, Flasher, & Shake from Coop.

    4. Added a new script named CoopToShooterAI.cs:
    Code (csharp):
    1. using UnityEngine;
    2.  
    3. public class CoopToShooterAI : MonoBehaviour {
    4.  
    5.     public void OnDamage(Transform attacker) {
    6.         gameObject.BroadcastMessage("DeductHealth", 1);
    7.     }
    8.  
    9.     public void OnDeath(Transform lastAttacker) {
    10.         gameObject.BroadcastMessage("CharacterDead");
    11.     }
    12. }
    5. Baked a NavMesh for the soldier to navigate around.

    6. To the player, I added a new script named ShooterAIToCoop.cs:
    Code (csharp):
    1. using UnityEngine;
    2.  
    3. public class ShooterAIToCoop : MonoBehaviour {
    4.  
    5.     public void Damage(float amount) {
    6.         gameObject.SendMessage("TakeDamage", amount);
    7.     }
    8. }
     
    DanielSnd likes this.
  5. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,697
    I've also had requests for this modification, which I'm actually using, so I figured I'd share it. It keeps players onscreen.

    In CamManager.cs, line 74 (at the end of Update()):
    Code (csharp):
    1. CalcFrustum();
    At the bottom of CamManager.cs (before the final curly brace):
    Code (csharp):
    1. private Plane[] frustumPlanes = new Plane[0];
    2. private Vector3 smallBox = new Vector3(0.1f, 0.1f, 0.1f);
    3.  
    4. private void CalcFrustum() {
    5.     if (Players.Count > 1) {
    6.         frustumPlanes = GeometryUtility.CalculateFrustumPlanes(camera);
    7.     }
    8. }
    9.  
    10. public Vector3 CenterPoint {
    11.     get { return (Players.Count == 1) ? LookVector : midCenter; }
    12. }
    13.  
    14. // Check if all players and the new point are all onscreen:
    15. public bool ArePlayersOnscreen(Vector3 point) {
    16.     if (Players.Count > 1) {
    17.         if (!GeometryUtility.TestPlanesAABB(frustumPlanes, new Bounds(point, smallBox))) {
    18.             return false;
    19.         }
    20.         foreach (var player in Players) {
    21.             if (!GeometryUtility.TestPlanesAABB(frustumPlanes, new Bounds(player.transform.position, smallBox))) {
    22.                 return false;
    23.             }
    24.         }
    25.     }
    26.     return true;
    27. }

    In PlayerInput.cs, line 38 (variable declarations):
    Code (csharp):
    1. public bool stayOnscreen = true; // Don't allow player to move if any players would be offscreen.
    2. public float screenMargin = 1f; // How far players are allowed from the edge of the screen (1=on the edge).
    In PlayerInput.cs, line 242 (in GetInput() before cM.TryMovement()):
    Code (csharp):
    1. // Keep players onscreen:
    2. if (stayOnscreen && CamManager.instance.Players.Count > 1) {
    3.     bool movingLeft = h < 0 && transform.position.x < CamManager.instance.CenterPoint.x;
    4.     bool movingRight = h > 0 && transform.position.x > CamManager.instance.CenterPoint.x;
    5.     bool movingBack = v < 0 && transform.position.z < CamManager.instance.CenterPoint.z;
    6.     bool movingForward = v > 0 && transform.position.z > CamManager.instance.CenterPoint.z;
    7.     if (movingLeft) {
    8.         if (!CamManager.instance.ArePlayersOnscreen(transform.position + screenMargin * Vector3.left)) {
    9.             h = 0;
    10.         }
    11.     } else if (movingRight) {
    12.         if (!CamManager.instance.ArePlayersOnscreen(transform.position + screenMargin * Vector3.right)) {
    13.             h = 0;
    14.         }
    15.     }
    16.     if (movingBack) {
    17.         if (!CamManager.instance.ArePlayersOnscreen(transform.position + screenMargin * Vector3.back)) {
    18.             v = 0;
    19.         }
    20.     } else if (movingForward) {
    21.         if (!CamManager.instance.ArePlayersOnscreen(transform.position + screenMargin * Vector3.forward)) {
    22.             v = 0;
    23.         }
    24.     }
    25. }
     
    DanielSnd likes this.
  6. MadMapp

    MadMapp

    Joined:
    Nov 15, 2012
    Posts:
    49
    need to find a way to access the score on player 1 at runtime? any1 know how to refrence its component and ultimatly the score variable?
     
  7. DanielSnd

    DanielSnd

    Joined:
    Sep 4, 2013
    Posts:
    382
    Thanks TonyLi! You're AWESOME! :D


    GameManager.instance.playerInfo[0].score

    The score is in the playerInfo class being used in the GameManager
     
  8. MadMapp

    MadMapp

    Joined:
    Nov 15, 2012
    Posts:
    49
    thanks daniel, i was trying to do GameManager.instance.playerInfo[pc.pId].score and all sorts of other wierd things :) appriciate your help, ill link the game when its done, ill also link the AI fixes i implemented to help relive lag on mobile, might be of use to some?
     
  9. Bullets42

    Bullets42

    Joined:
    Jun 26, 2012
    Posts:
    13
    Hello!

    Great looking asset here what I love already is the quality seems very good nothing seems rushed and that alone makes me eager to get my hands on this. However I had a question I read in your post you mentioned the character would have no issues running up and down the Y axis however the gun would shoot straight ahead causing a hill ahead to block the shots if the Y axis of the hill is higher then the shots beings fired or the spot of character for which plane he stands on that is. Now the issue is I am not a programmer so that's why I had to ask you before making my decision on this purchase. Would I be able to perhaps get your assistance with making the gun aim stay set at a certain height but also automatically adjust to the ground terrain under neath? Or something around those lines, maybe it would be better to make a aim cursor that simply rest on objects it collides with. Then I could aim at a guy on a cliff above and if my cursor is aimed properly I should be able to make the shots under my own control in accuracy.

    Anyhow thats a big concern for me because I would really love to make a top down shooter game out of this seems to have everything to help me get started for the style game I want but the only thing that is stopping me really is not knowing if I am capable of making that happen above.

    p.s.
    Last question for you would be do you plan on adding more features or bug fix's I seen you just recently went through a long distance move and probably pretty busy but I am just curious how you felt about this products future updates and such. I've had my eye on this for a while.
     
  10. chrisabranch

    chrisabranch

    Joined:
    Aug 15, 2014
    Posts:
    146
    hI,
    I'm using your kit along with complete physics platformer kit.
    i would like to merge the two kits and use control freak as the mobile controller. is this possible?

    p.s
    i am having trouble with the input settings merging the two and CNControls got a update and is no longer working
     
    Last edited: Oct 20, 2014
  11. schmosef

    schmosef

    Joined:
    Mar 6, 2012
    Posts:
    852
    It looks great. I picked it up today during the sale.
     
  12. jamesloymartin

    jamesloymartin

    Joined:
    Oct 22, 2014
    Posts:
    3
    Hi man. Played the demo, very cool.

    I'm new to Unity, so I've gotta ask: Can I buy this and edit it like crazy where you can hardly even recognize it? New textures, animations, weapons, character selection, mechanics, UI and everything? I just want a base to build off of and the end product could be a totally different kind of game.

    And when you come out with updates, does one get them automatically when you release them?

    Total newb question, I know.

    Thanks,
    James
     
  13. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,697
    I'm just replying as another customer of this kit. Here are my experiences with it, in case it helps you make a decision while the 24-hour sale is on today.
    • Daniel wrote great instructions for how to change the player character model/animations, weapons, and enemies. It's pretty easy to swap in your own.
    • All players have to use the same prefab (character model), but they can be tinted different colors. To support different models for different players, you'd have to make a few small edits to the C# code.
    • On the plus side, the C# code is short and clear. If you're comfortable with C#, you can jump in and make changes fairly easily. (On the minus side, it's not documented very much, but it's short and simple enough that you can still understand it.)
    • Other things you'd have to modify the code for: menu UI, mechanics, character selection. For the menu UI, if you don't code, you could use another product like Scene Manager.
    • Since it uses standard Unity techniques for everything, you can drop the players into any environment. I tested four players running through several environment assets on the Asset Store: a top-down fantasy level, a post-apocalyptic city, sci-fi corridors, etc. And of course you can use the built-in procedural generator to make your own random levels at runtime.
    • The only catch with some environments is that characters always shoot at their own height. They can't shoot up or down, unless you modify the code to do this.
    • It works with lots of input devices right out of the box.
    Despite the few shortcomings above (it's only at version 1.1 after all), the kit does everything it claims to do, and it's a lot of fun to play. If you're playing single player on levels that don't have altitude changes, you'd never notice any issues -- and even with the same player model for all players and the inability to shoot up or down, my friends and I still had a ton of fun shooting up the place. :)

    Yes, the Asset Store always has the latest version that the author has submitted. If you've bought it at any point, you can always download the latest version.
     
    Bullets42 likes this.
  14. jamesloymartin

    jamesloymartin

    Joined:
    Oct 22, 2014
    Posts:
    3
    Wow, thanks for all the info. Sounds pretty good and I could make my own environments. Thanks, man.
     
  15. cookimage

    cookimage

    Joined:
    Sep 10, 2012
    Posts:
    729
    Has anyone had problems with the player model moving higher as you move around. I added shadows and can see the model move upwards while the character controllers collusion stays on the ground. I have no idea why the model will slowly start to move higher and higher as you move around.
     
  16. DanielSnd

    DanielSnd

    Joined:
    Sep 4, 2013
    Posts:
    382
    That sounds good thanks! :D

    Not sure, Haven't really stopped to think how I'd solve that problem, give me a few days to think about it, can't promise anything atm =x

    About future updates, right now I'm pretty busy with the masters degree, I do have some time this weekend I intend to use to make the Wave Spawner I mentioned before and a simple triggers system that could be used to trigger that and simple camera animations and such. I wouldn't actively expect much more updates beyond that, (Might happen, but also might not =x)

    That sounds like a crazy idea o_O My kit uses charactercontroller and pretty much no real "rigidbody" physics (apart from the coins), CPPK uses pretty much all rigidbody physics, I wouldn't imagine they would work well together, what exactly are you trying to accomplish?

    I will take a look at CNControls and see if it's something I can fix and release a new update, thanks for letting me know :).

    Well, yes D: Technically you can do anything, but you do might have to learn how to do things, and even have to learn how to code if you don't know already. I've been using the kit as a base to "make a totally different kind of game", it saved me a lot of time not having to do recode all the basics and jumping right to the specifics.

    That's an awesome review <3 thanks, and thanks again for all the code help you provided! :D

    - The different player prefabs is a fairly easy fix :eek: I'll make the necessary changes
    - Now I really want to make the shooting up and down hills :( Will have to think more about how to fix this, maybe make a raycast down in front of the character to check if I'm going up or down a hill and adjust my shooting based on the difference in height from a raycast done straight down from the character's body and a raycast done in front of the character down. Can't promise anything but I'll try my hand at it.
    - I really should comment my code more :( Sorry about that.
     
  17. DanielSnd

    DanielSnd

    Joined:
    Sep 4, 2013
    Posts:
    382
    It sounds to me that it's colliding with something underneath him and moving higher because of that. Did the shadow you added happens to have a collision he could be colliding with?
     
  18. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
    Hey Tony, wondering which AI solution you went with.
     
  19. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
  20. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
    I just tried the asset with the new update of CNJoystick and getting errors:

    Assets/COOP Action Game Kit/_Scripts/Player/PlayerInputMobile.cs(22,30): error CS1061: Type `CNJoystick' does not contain a definition for `JoystickMovedEvent' and no extension method `JoystickMovedEvent' of type `CNJoystick' could be found (are you missing a using directive or an assembly reference?)
     
    hippysniper likes this.
  21. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,697
    Behavior Designer and my own sensory perception system. I almost went with PlayMaker, since a simple FSM is more than sufficient for my AI needs in this project.

    This kit is all about the camera and character controllers, so there really wouldn't be too much left if you replaced them -- just the procedural level generator, bullets, and enemy AI. Also, Adventure Camera doesn't keep multiple players onscreen, so it would take a little extra work to handle multiplayer.
     
  22. cookimage

    cookimage

    Joined:
    Sep 10, 2012
    Posts:
    729
    Nope is basic unity shadow from a light so no collusion on it. And the character controller has the collusion on and that stays on the ground , its the mesh that keeps going up. as if it gets positioned by code as it should not move up from the character controllers collidere
     
  23. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,697
    Does the mesh object have a collider on it, too? Or is the weapon attached to the hand colliding perhaps?
     
  24. cookimage

    cookimage

    Joined:
    Sep 10, 2012
    Posts:
    729
    Thanks for the help, it turns out i had to change the animation setup on the character I am using to be rooted, so nothing to do with scripts. So far I have been working with this kit and am supper impressed with it all works perfectly as it states. One thing that would be nice is a way to change the UI easily to use NGUI with messaging buttons. As how its setup at the moment for a non programer is note easy to use NGUI for ui. Thank goodness I have a programer on Staff that can fix that for us lol. Supper good package, think one of the bets ones I have bought from Asset Store!!
     
    DanielSnd likes this.
  25. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
    Thanks Tony
     
  26. hippysniper

    hippysniper

    Joined:
    May 9, 2014
    Posts:
    5
    Any luck with the mobile controls setup or is the issue unresolved?
     
  27. DanielSnd

    DanielSnd

    Joined:
    Sep 4, 2013
    Posts:
    382
  28. Espra

    Espra

    Joined:
    Nov 8, 2014
    Posts:
    7
    Hi, first this package is really fun, i like :)
    I have not really much experience with Unity3d and scripting in C#

    Have two question at now

    1. Any Video of Tutorials about package?

    2. Have use to replace a enemy on my Own, everything is fine, but -run-, -attack- animation doesn't work for me.Always stop the Animation when Enemy Run.Need any change on Script ? Any Idea ???
     
  29. hippysniper

    hippysniper

    Joined:
    May 9, 2014
    Posts:
    5
    thanks heaps for the updated control script 5 star review comming up =)
     
  30. Espra

    Espra

    Joined:
    Nov 8, 2014
    Posts:
    7
  31. eridani

    eridani

    Joined:
    Aug 30, 2012
    Posts:
    655
    Any idea when the version 1.2 update will be released? I'm still waiting for the namespaces fix. Thank you
     
  32. DanielSnd

    DanielSnd

    Joined:
    Sep 4, 2013
    Posts:
    382
    1. Not yet :( I want to make some though, not sure when.
    2. Weird, I don't quite understand what you mean. Did you replace the stuff on the mecanim animation controller?

    Not sure :( I'm pretty busy this month, will get 1 month break in december in which I'll have time to work on it :)
     
  33. Brendonm17

    Brendonm17

    Joined:
    Dec 9, 2013
    Posts:
    43
    Hey Daniel! Im not sure if you remember me, but i used to watch you modeling videos on your channel! I purchased this kit the other day, and i am very impressed! :) But i did found one problem that i have "fixed".. The draw calls! I noticed the draw calls exceeding THOUSANDS, and that is a BIG no no for a fast paced game. So i downloaded Draw Call Minimizer from the asset store, and with a bit of Integration.. I got the draw calls down to 19 on My machine! :) that means you might be able to make procedural on mobile! if your interested, ill tell you how i went about this.
     
    eridani and TonyLi like this.
  34. DanielSnd

    DanielSnd

    Joined:
    Sep 4, 2013
    Posts:
    382
    You mean drawcall minimizer can batch stuff on run-time? o_O Sounds like a miracle to me. Reducing drawcalls is a normal process when done beforehand, but something that would do it on runtime on something that was just put together procedurally on the spot sounds too good to be true.
     
  35. Brendonm17

    Brendonm17

    Joined:
    Dec 9, 2013
    Posts:
    43
    It's not though! All I had to do was when the map was finished generating, I added a line of code that added the draw call minimizer to one of the generators child objects. The script then automatically does its work in the start function, the only drawback is that there is a few seconds of lag at the start of the scene. Plus you have to set up textures a certain way too.
     
  36. eridani

    eridani

    Joined:
    Aug 30, 2012
    Posts:
    655
    Wow Brendon can you give more details or step by step? Using COOP procedural on mobile would be awesome! Thanks for sharing your discovery!
     
  37. schmosef

    schmosef

    Joined:
    Mar 6, 2012
    Posts:
    852
    Yes @Brendonm17, please share with the rest of the class.
     
  38. Brendonm17

    Brendonm17

    Joined:
    Dec 9, 2013
    Posts:
    43
    I'm making a video tut right now.
     
  39. Brendonm17

    Brendonm17

    Joined:
    Dec 9, 2013
    Posts:
    43
    Oops, my computer does not want to record right now :confused:... But here is what i did anyways. I created a new project. Added Daniels kit to it, and the draw call minimizer one... BUT, only import the "NEW" folder under "Scripts". after that add the two lines of code under.. um, lets say 1148.
    Code (CSharp):
    1. containerFilled.AddComponent<DCM.DrawCallMinimizer>();
    2. containerWallRooms.AddComponent<DCM.DrawCallMinimizer>();
    After that, just test it out! the draw calls got down to 19 with my own models & project... Even though with a stock project they don't get too low, this is still a help. In the stock project, it brought my frames upwards of 50, while before i was getting a rough 20-25. With your own models, you can achieve a 19 like me.
     
  40. schmosef

    schmosef

    Joined:
    Mar 6, 2012
    Posts:
    852
    Is this the asset you are using for the draw call minimizer or is it something else?
     
    Last edited: Nov 15, 2014
  41. Brendonm17

    Brendonm17

    Joined:
    Dec 9, 2013
    Posts:
    43
    schmosef likes this.
  42. DanielSnd

    DanielSnd

    Joined:
    Sep 4, 2013
    Posts:
    382
    That sounds awesome indeed! :D Thanks for sharing.
     
    Brendonm17 likes this.
  43. eridani

    eridani

    Joined:
    Aug 30, 2012
    Posts:
    655
    What did you do to your own models that are different from the stock models, may I ask?
     
  44. Brendonm17

    Brendonm17

    Joined:
    Dec 9, 2013
    Posts:
    43
    Way less polys & tris.
     
  45. Espra

    Espra

    Joined:
    Nov 8, 2014
    Posts:
    7
     
  46. DanielSnd

    DanielSnd

    Joined:
    Sep 4, 2013
    Posts:
    382
    If you want to send me the project via private message or something I can take a look and see what the problem is.
     
  47. Brendonm17

    Brendonm17

    Joined:
    Dec 9, 2013
    Posts:
    43
    Hey Daniel, where did you learn to model and animate so good? I started using blender after getting inspired by your tuts, and am having a hard time making realistic animations
     
  48. DanielSnd

    DanielSnd

    Joined:
    Sep 4, 2013
    Posts:
    382
    I went to a school of 3D Animation & VFX, that got me started, after that I studied online/by myself. Animation is very complex, requires a lot of dedication to learn.
     
  49. Brendonm17

    Brendonm17

    Joined:
    Dec 9, 2013
    Posts:
    43
    Wow! I Am currently a high school student working towards college, to get my bachelors (or even my masters!) in computer science (programming). Over the last few months though, I have been practicing modeling and animating! Once I "finish" my character and animations, I'll be sure to post them if your interested in what your (and others) teachings have accomplished:D!
     
  50. DanielSnd

    DanielSnd

    Joined:
    Sep 4, 2013
    Posts:
    382
    Sure thing :) feel free to send stuff to me anytime.