Search Unity

  1. 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

Modular Traffic [PlayMaker AI] & 3D Road models

Discussion in 'Assets and Asset Store' started by 600, May 14, 2015.

  1. josker

    josker

    Joined:
    May 10, 2014
    Posts:
    45
    I thought the voucher was for half price roads, was a nice surprise to see it was free, thank you.
    Upgraded to traffic, already had car set-up.
    Will have a good look at it over the next few days.
    Thanks again.
     
    600 likes this.
  2. movra

    movra

    Joined:
    Feb 16, 2013
    Posts:
    571
    Resaving the PSD files as 8 bit per channel instead of 16 bit per channel seems to do the trick.
     
    600 likes this.
  3. 600

    600

    Joined:
    Dec 18, 2013
    Posts:
    339
    Wow awesome finding @movra !
    Thanks for posting! Hope this will fix the issue for others too.
     
  4. 600

    600

    Joined:
    Dec 18, 2013
    Posts:
    339
    Hi, this is now fixed in version 1.1.3
     
    movra likes this.
  5. 600

    600

    Joined:
    Dec 18, 2013
    Posts:
    339
  6. Jack62Lewis

    Jack62Lewis

    Joined:
    Jun 17, 2013
    Posts:
    105
    Hey,

    How hard would it be to make this asset work with my own games AI? Cause using my own scripts my AI do a lot more than walk around. Talk, fight, follow etc.
    And would it be hard to use this asset to have things like traffic jams, cars not following traffic or cars going off road and stuff?

    Is this asset like a framework for adding those sort of things?

    Thanks,
    Jack
     
  7. 600

    600

    Joined:
    Dec 18, 2013
    Posts:
    339
    Hello,
    Thanks for your interest.
    You can use your own ped AI and just take the traffic light logic. Asset's ped AI are Unity NavMesh agents.

    Cars pick the front road segment and takes a random direction that is available, off road waypoints could be added to be used in some circumstances. Custom stuff and other behaviours for traffic would have to be made by you as desired.
    Playmaker is very flexible in this case. Traffic logic can be extended with racer AI (from Car Setup asset for example) to have some action, but other than that this asset contains AI that just drives around following traffic lights and stopping for obstacles.

    This is not a framework, but a template asset, open for custom features to be added.

    If you want/can share specific stuff you want to implement, I can give you a hint where to look and what to change, you can pm me any time.
     
  8. Jack62Lewis

    Jack62Lewis

    Joined:
    Jun 17, 2013
    Posts:
    105
    Sweet! Thanks for that.

    So cars don't use nav mesh agents? Also, how would changing road, pavement, lamp post and traffic light graphics work? Would it be a simple case of swapping meshes more or less?

    Thanks,
    Jack
     
  9. 600

    600

    Joined:
    Dec 18, 2013
    Posts:
    339
    Yes, cars don’t use NavMesh, only pedestrians.

    Yes you can make custom prefabs with your own mesh objects only transferring the invisible logic from my prefabs. I used 50x50 size for convenience, but yours can be any rectangle proportion.
     
    Jack62Lewis likes this.
  10. Jack62Lewis

    Jack62Lewis

    Joined:
    Jun 17, 2013
    Posts:
    105
    Hey, I'm currently testing some stuff out.

    Adding the prefabs roads to the scene and then pedestrians works as expected. The traffic lights dictating the wandering actions of the people etc. But when I add car prefabs they don't move and when I add the car spawner object it spawns a car but it goes crazy.

    PS I acidentily didn't open a new project before importing >.< Everything seems okay my project wasn't all that complex. Will this cause huge problems?

    Thanks,
    Jack
     
  11. 600

    600

    Joined:
    Dec 18, 2013
    Posts:
    339
    If you use in your current project please check if you have set Tags and Layers + Physics Manager as in the ReadMe, does this help?

    And don’t forget to make a backup of your project before importing new stuff ;)
     
  12. Jack62Lewis

    Jack62Lewis

    Joined:
    Jun 17, 2013
    Posts:
    105
    All seems to be in order. But right now the car follows the road. Waits for green light. Keeps following road and then just glides backwards to the right after a few more seconds.
    Is adding the AI_Car spawner object to one of the lanes on the road the correct way to add cars?
     
  13. 600

    600

    Joined:
    Dec 18, 2013
    Posts:
    339
    By default there are one AI_Cars scene object that deals with spawning cars, it creates the AI_Car object that spawns a random vehicle, it should start at first waypoint and look at second in a given road lane.

    If you changed this, can you send me some images for reference (screenshots with FSM please send as private message)? Can’t imagine the case car gliding backwards, maybe waypoints changed places?
     
  14. Jack62Lewis

    Jack62Lewis

    Joined:
    Jun 17, 2013
    Posts:
    105
    Where is the first waypoint defined?
     
  15. 600

    600

    Joined:
    Dec 18, 2013
    Posts:
    339
    Scene object "AI_Cars" FSM, a state after "Find 01"; "Find 02" states.
    Had a chance to import it into fresh project to see how it all works?
     
  16. Jack62Lewis

    Jack62Lewis

    Joined:
    Jun 17, 2013
    Posts:
    105
    Yes, I've opened a new project. Made a circle road track and added a car AI object into the scene. When the car spawns it just starts moving sideways.
     
  17. 600

    600

    Joined:
    Dec 18, 2013
    Posts:
    339
    There are two different objects, one is the scene object “AI_Cars” the spawner (see Demo scene), that creates the “AI_Car” prefab and gives the first waypoint group info to it (AI_Cars gives to AI_Car). Names are close, one is the scene object and one the prefab. For reference please check the demo scene in action.
    So the system should go like this:
    1. Scene object AI_Cars spawner
    2. AI car controller is created (from prefab)
    3. AI car controller spawns a random vehicle to drive
     
  18. Jack62Lewis

    Jack62Lewis

    Joined:
    Jun 17, 2013
    Posts:
    105
    Ah, adding the AI_Cars object from the test scene is working to give me proper function cars in my own scene when I hit "m". Thanks!
     
    600 likes this.
  19. 600

    600

    Joined:
    Dec 18, 2013
    Posts:
    339
    Last edited: Apr 14, 2017
  20. GeometriX

    GeometriX

    Joined:
    Oct 26, 2015
    Posts:
    7
    Hi, this asset looks great, but I'd like to know a couple of things before I commit to a purchase:

    1) I noticed that in the web demo the cars drive on the right-hand-side of the road. Can I change them to drive on the left?
    2) You mentioned that the AI cars drive to random waypoints. Is it possible to set a specific car to drive to a specific waypoint? I'm looking at creating an open-world game with player-owned, but not directly controlled vehicles. The player would select a waypoint on the map and then the car would automatically drive there. They must also be able to stop the car at any time to exit it. Is this possible?
    3) Is there a mechanic for overtaking and/or setting speed limits on certain roads?
    4) Is there a way to lock certain routes from the player. For example a highway that can only be accessed if the player pays a toll to use it.

    Thanks in advance!
     
  21. 600

    600

    Joined:
    Dec 18, 2013
    Posts:
    339
    Hello, thanks for your interest.

    1) It is possible, just tested. It can be done manually tho, preparing all prefabs, changing scale for X to -1 on some parts of road models & logic. Later I can send you some screenshots how to do it.

    2) At the moment no, there are no GPS system in place. However I have plans to create A to B logic, but can’t give you any ETA on this. I have some ideas how to achieve this with a help of navigation agent, but not tested this, I will need this feature later in my project too. When I reach this milestone I will share this feature with this asset too.
    For stopping a car any time, sure it can be done by adding one bool to the logic to call a brake, let me know if you need help on this.

    3) Yes you can create a trigger object on the start lane to set the max speed value higher for passing cars, also set back to default when leaving that area. This feature is not implemented by default yet, I can give you tips how to do it as well.

    4) All cars have obstacle detection, so they stop if something is in front, so you can make a toll barrier with collider to stop anyone willing to go through until a player does an interaction.

    Let me know if you have further questions about the asset.
     
  22. GeometriX

    GeometriX

    Joined:
    Oct 26, 2015
    Posts:
    7
    Okay, awesome, thanks for your prompt response!
     
  23. Murph2che

    Murph2che

    Joined:
    Apr 12, 2016
    Posts:
    2
    Hi! I really like your Unity package! Is there a way I can start a scene with a number of cars preexisting versus generating them with a key once the game is in play?
     
  24. 600

    600

    Joined:
    Dec 18, 2013
    Posts:
    339
    Hi, yes you can make a small change in the input FSM making it to loop x times at startup to spawn the set number of vehicles/peds. I have a screenshot of this setup already as it was sent to other users too. Contact me on support email to receive it, thanks for your interest!
     
  25. Murph2che

    Murph2che

    Joined:
    Apr 12, 2016
    Posts:
    2
    Thanks - I just shot you a note there! I really appreciate the help!
     
    600 likes this.
  26. ashwinFEC

    ashwinFEC

    Joined:
    May 19, 2013
    Posts:
    35
    The mobile demo crashes when I build to iOS with IL2CPP

    I think the problem is when the action Find Child in PedStopper template is looking for 4 PedTriggers children but there are only 2 available, like in MT_Intersection_T. And then the Get Component action will perform on a null object and then crashes.

    You might want to add null checks in the templates
     
  27. 600

    600

    Joined:
    Dec 18, 2013
    Posts:
    339
    Thanks a lot for the finding and solution! I will update them asap!
     
  28. ashwinFEC

    ashwinFEC

    Joined:
    May 19, 2013
    Posts:
    35
    I did some testing. The problem wasn't that GetComponent performs on a null object since the script already checks for nulls. The problem is that the GetComponent uses Reflection to get the type which often doesn't work properly in IL2CPP.

    Therefore you should use a custom action to get the collider. Like this one:
    Code (CSharp):
    1.  
    2. using UnityEngine;
    3.  
    4. namespace HutongGames.PlayMaker.Actions
    5. {
    6.     [ActionCategory(ActionCategory.UnityObject)]
    7.     [Tooltip("Gets a Collider Component attached to a GameObject and stores it in an Object variable. NOTE: Set the Object variable's Object Type to get Collider component of that Collider type. E.g., set Object Type to BoxCollider")]
    8.     public class GetColliderComponent : FsmStateAction
    9.     {
    10.         [Tooltip("The GameObject that owns the component.")]
    11.         public FsmOwnerDefault gameObject;
    12.  
    13.         [UIHint(UIHint.Variable)]
    14.         [RequiredField]
    15.         [Tooltip("Store the component in an Object variable.\nNOTE: Set theObject variable's Object Type to get a Collider component of that Collider type. E.g., set Object Type to BoxCollider to get the BoxCollider component")]
    16.         public FsmObject storeComponent;
    17.      
    18.         [Tooltip("Repeat every frame.")]
    19.         public bool everyFrame;
    20.  
    21.         public override void Reset()
    22.         {
    23.             gameObject = null;
    24.             storeComponent = null;
    25.             everyFrame = false;
    26.         }
    27.  
    28.         public override void OnEnter()
    29.         {
    30.             DoGetComponent();
    31.  
    32.             if (!everyFrame)
    33.             {
    34.                 Finish();
    35.              
    36.             }
    37.         }
    38.  
    39.         public override void OnUpdate()
    40.         {
    41.             DoGetComponent();
    42.         }
    43.      
    44.         void DoGetComponent()
    45.         {
    46.             if (storeComponent == null)
    47.             {
    48.                 return;
    49.             }
    50.          
    51.             var targetObject = Fsm.GetOwnerDefaultTarget(gameObject);
    52.          
    53.             if (targetObject == null)
    54.             {
    55.                 return;
    56.             }
    57.  
    58.             if (storeComponent.IsNone)
    59.             {
    60.                 return;
    61.             }
    62.  
    63.             storeComponent.Value = targetObject.GetComponent<Collider>();
    64.         }
    65.     }
    66. }
    I have tested it and the Demo scene now works on IL2CPP builds
     
  29. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    4,684
    I'm curious about this issue. In general reflection should work on IL2CPP. Is this a case where Mono works on iOS but IL2CPP does not? If so, I would love to get a bug report about this so that we can correct it.
     
  30. 600

    600

    Joined:
    Dec 18, 2013
    Posts:
    339
    Thank you for the action! I have not tested it. On what Unity version are you building?
    Now I am curious if it’s a Unity bug as @JoshPeterson mentioned, or should I actually update the pack?
     
  31. ashwinFEC

    ashwinFEC

    Joined:
    May 19, 2013
    Posts:
    35
    @JoshPeterson I have submitted a report, case nr. 798411

    @600 I'm using the latest patch release 5.3.4p6 and PlayMaker 1.8.0f43.
     
  32. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    4,684
    @ashwinFEC

    Thanks, we will investigate this bug report.
     
  33. 600

    600

    Joined:
    Dec 18, 2013
    Posts:
    339
    Thanks for reporting @ashwinFEC
    Will follow the progress of the ticket before I update the asset pack.

    @JoshPeterson Thanks for looking at this!
     
  34. ashwinFEC

    ashwinFEC

    Joined:
    May 19, 2013
    Posts:
    35
    OK I did some additional testing and I don't think it's a bug. Since most code in PlayMaker relies on reflection but barely has code in it that implicitly tells which types it uses the Stripping process takes out the necessary classes.

    You can prevent this by adding a link.xml file with these lines in it

    Code (JavaScript):
    1. <linker>
    2.        <assembly fullname="UnityEngine">
    3.            <type fullname="UnityEngine.Collider" preserve="all"/>
    4.            <type fullname="UnityEngine.BoxCollider" preserve="all"/>
    5.            <type fullname="UnityEngine.WheelCollider" preserve="all"/>
    6.        </assembly>
    7. </linker>
    this will make the Demo scenes work in a IL2CPP compiled version.
     
  35. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    4,684
    After some investigation, I don't think that this is a bug, but rather an odd behavior related to code stripping. This occurs on IL2CPP because the IL2CPP build toolchain always strips unused managed code. The Mono tool chain does not always strip, so this does not happen there. I'll try to explain what is occurring.

    The problem is that the UnityEngine.BoxCollider type is being removed from the UnityEngine assembly. That type is accessed via only reflection in scripts and assemblies project, so the code stripper does not see that it is being used at build time. Note that the Box Collider component is used in the scene, but the code stripper only uses the scripts in the projects as root to determine what to preserve. So it misses the use of the Box Collider.

    There are two ways to work around this issue. First, you can add a dummy game object with a script that uses a BoxCollider. I used this one:

    Code (CSharp):
    1. public class NewBehaviourScript : MonoBehaviour {
    2.  
    3. public BoxCollider test;
    4.  
    5. // Use this for initialization
    6. void Start () {
    7. }
    8.  
    9. // Update is called once per frame
    10. void Update () {
    11.  
    12. }
    13. }

    Second, you can add a link.xml file to the Assets directory in the project to inform the code stripper to keep the BoxCollider type:

    <linker>
    <assembly fullname="UnityEngine">
    <type fullname="UnityEngine.BoxCollider" preserve="all"/>
    </assembly>
    </linker>


    You can find more details about the link.xml file here: http://docs.unity3d.com/Manual/iphone-playerSizeOptimization.html

    My preference would be to use the link.xml file, as it clearly indicates the intent to preserve something that would otherwise be stripped. However, both options will work.
     
  36. 600

    600

    Joined:
    Dec 18, 2013
    Posts:
    339
    Thank you for tests @ashwinFEC @JoshPeterson !

    Now I am thinking, maybe @Alex Chouls could look at this as well, because this could affect all users using PlayMaker GetComponent from Template in iOS.
    So adding additional script in my demo would be a work around not a core problem fix.
     
  37. ashwinFEC

    ashwinFEC

    Joined:
    May 19, 2013
    Posts:
    35
    I went trough the PlayMaker forum and it's known that a link.xml file has to be added to prevent stripping of necessary classes from the assembly. They even created a Linker Wizard to streamline the link.xml creation http://hutonggames.com/playmakerforum/index.php?topic=11126.0

    A link.xml file is the best solution if types are only accessed trough reflection. It's not a workaround. That's just how the stripping process in Unity works. The guys from PlayMaker can only fix this if they stopped using reflection, which would basically go against PlayMakers modular system.
     
  38. 600

    600

    Joined:
    Dec 18, 2013
    Posts:
    339
    Thank you for the info! I have no experience with building/publishing with iOS, did not know about it. Will check it out and update the asset accordingly.
     
  39. 600

    600

    Joined:
    Dec 18, 2013
    Posts:
    339
    A quick note:
    Now PlayMaker 1.8.1 have Animator actions included by default, if you are importing the asset in Unity 5.3+ with PM 1.8.1+ uncheck the Animator folder to avoid duplicate errors.
    Ignore this message for earlier versions.
     
  40. 600

    600

    Joined:
    Dec 18, 2013
    Posts:
    339
    ^ Disregard this quoted message, as now Unity import automatically detects the duplicates and ignores them, so import All as before.
     
  41. Hermonirr

    Hermonirr

    Joined:
    Dec 23, 2013
    Posts:
    54
    Hi,

    I'm looking at Modular Traffic for a project. I need to import a model into Unity that includes sidewalks and roads, and have the cars and pedestrians behave appropriately. How can I do this with a pre-built, irregular model?
    1. I understand the pedestrians are NavMesh agents so I can just bake the navmesh for the sidewalks. How would I define crosswalks?
    2. What should I do to define road models as "roads" so the cars from Modular Traffic would drive them?
    3. Do the cars need colliders at the road sides?
    4. Do the cars automatically keep to the right, no matter what's the road width?

    Thank you very much.
     
  42. 600

    600

    Joined:
    Dec 18, 2013
    Posts:
    339
    Hi,

    1. Yes they are NavMesh agents, sidewalks and crosswalks are separate mesh objects so you can define them walkable, if you have road in one piece, you can bake invisible objects specially placed for crossings.

    2. Cars find a road segment and follow waypoints, so you can set them for your requirements.

    3. No colliders on road sides.

    4. Cars follow waypoints, so you set how far to the right they must drive.

    Here are some preview screenshots from my WIP project using other road models.

    MT_Intersection_NavMesh.jpg MT_Intersection_preview1.jpg MT_Intersection_preview2.jpg MT_Road_Waypoints_withModules.jpg MT_Road_Waypoints.jpg
     
  43. Hermonirr

    Hermonirr

    Joined:
    Dec 23, 2013
    Posts:
    54
    I bought the plugin and looked at the examples. The crossroads seem to have a lot of navigation aids in the hierarchy. For basic traffic - no traffic lights or crossings - how many waypoints are needed for a four way crossroad? Is it the only needed addition to a mesh?
    In order to keep their lanes, should the road segments also have waypoints along the way, or can you do without?
    Every user brings his own mesh and sets it up, that's why I need mininal setup.
     
  44. 600

    600

    Joined:
    Dec 18, 2013
    Posts:
    339
    Do I understand correctly, they are driving straight? You would need 3 waypoints per lane. Maybe you can contact me on support@pamani.net with screenshots?
     
  45. daniel19940930

    daniel19940930

    Joined:
    Jul 29, 2015
    Posts:
    2
    Hello,

    This asset is pretty great and it seems to be the wright thing I need. However, I'd like to check some things before purchasing. By the way, I intent to use this asset to help me with my driving school game.

    1) Would it be easy for me to detect the car (control by player) if the player use the indicator or not when it's going to turn right/left.

    2) I would like to make some circumstances as some stages for the game, so is it possible or easy for me to set some specific routes for cars and pedestrians, and even to control the traffic lights ?

    3) Is it possible that making the whole scene(roads, traffice items, buildings...) generate by itself if I use some road-generation algorithms ? (Giving some parameters(like city scales, #pedestrians, #cars...) for a function I wrote to make it generate the scene)

    Thank you in advance:)
     
  46. 600

    600

    Joined:
    Dec 18, 2013
    Posts:
    339
    Hello,

    1) You could add triggers in intersection prefabs that detects entry and exit points, then check if indicator was on or off. To be clear this asset included traffic car controller and not player driven controller, for this I can suggest my other asset “Car Setup For Playmaker”.

    2) Yes you can change target destination for pedestrians easily, now they just choose random waypoint.

    For cars however it would be a bit more work as you would need to predict direction you want a car to drive. So when a car gets the first road group (road prefab) instead of random direction, you would need to set which waypoints to follow, doing this for x amount of times (road sections) until it goes to random, for example. (On support email I could point you in the right direction in FSM setup of what I mean). You can control traffic lights also, now they go on in loop, could add an event in FSM to call if you want them to change in specific state.

    3) I have not done this so I don’t have a right on solution for you. I imagine it is quit possible and car AI would understand instantiated roads ahead, only thing for now is that there can not be dead-end streets, they must connect in circles somewhere. Another issue would be for pedestrians, if I remember correctly Unity NavMesh can’t bake at runtime, so there would be needed other navigation implementation.

    Thank you for the interest and let me know if you have further questions.
     
    Last edited: Apr 14, 2017
  47. daniel19940930

    daniel19940930

    Joined:
    Jul 29, 2015
    Posts:
    2
    Thank u so much for answering:)
     
  48. Banksy

    Banksy

    Joined:
    Mar 31, 2013
    Posts:
    363
    just purchased & am now setting up with SIMPLEVehicles.

    How can I go about swapping out the generic blue vehicles for Simple ones ?
     
  49. 600

    600

    Joined:
    Dec 18, 2013
    Posts:
    339
    Hello, thank you for the purchase.

    After you have imported the Traffic pack, please check the asset folder there will be SimpleTraffic.zip, unzip it outside the project and import the given package in to the project. The Simple prefabs was made using Simple Town vehicles, I don’t have Simple Vehicles asset to test it, perhaps prefabs will find their references? Let me know how it goes for you.
     
    Last edited: Aug 29, 2016
  50. Banksy

    Banksy

    Joined:
    Mar 31, 2013
    Posts:
    363
    I have Simple Town + Modular Traffic (build 0709-1) loaded I hit play it loads and I can see all the buildings + roads.. but no vehicles or pedestrians ... woops hold on.. I need to Hit "B" & "M" to populate the scene.... Oooooeewww there ya go... and we have a population.
    Everything is awesome ! uummm.... not quite... hhmm.. those cars
    sure are prone to traffic jams. Early days, I'll take a bit of time and get a feel for the possibilities.
     
    Last edited: Aug 29, 2016
    600 likes this.
unityunity