Search Unity

Communicating with objects

Discussion in 'Navigation' started by andres3341, Sep 21, 2017.

  1. andres3341

    andres3341

    Joined:
    Sep 21, 2017
    Posts:
    5
    Hello! I'm trying to make a city simulation with cars and pedestrians moving around. Instead of each one having a route I would like to add some objects at the intersections to "give" them a direction to go but I don't really know how to. All this in running time.

    For example, at the first intersection tells the car to go to the left and then the next one to the right, etc.
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    some ideas
    - waypoints (could be empty gameobjects), so can check that after distance to current target waypoints is < 0.1, target next waypoint
    - triggers, https://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html
    - intersections could have empty gameobjects that shoot raycasts down, if the ray hits passing car, they can give direction to that car
    - cars could raycast forwards, if dummy intersection collider is detected, check where to turn
    - if its huge city with lots of objects, some kind of quad/octree could work to get closest object faster (so if closest object to car is turn_left_marker, and distance to it is near enough, can ask car to do turn..)
     
    France_DLGG and andres3341 like this.
  3. andres3341

    andres3341

    Joined:
    Sep 21, 2017
    Posts:
    5
    I'll have a look at everything you just told me! It's gonna be a medium city, and depends on the hour / day of the week / etc is gonna choose one direction or other. For example, on Friday people will go to the beach if it's summer, etc.

    I'll be working on this until I have it done so i'll post all my updates here. Thanks!
     
  4. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    actually, do you need physics / colliders on those cars?

    also if the map is grid based, then its easier to check what to do on each cell, like if cell is cross section, can randomly pick available turn (if next cell in left or right is road)
     
  5. andres3341

    andres3341

    Joined:
    Sep 21, 2017
    Posts:
    5
    No, I'm just caring about simulating city traffic movements. I'm using Mapbox plugin for adding the map as a layer. I would like to give a certain movements to the car in order to simulate it, so I would like to add routes to them but I'm still trying to figure how it can be done.

    Thanks!
     
  6. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    ok, that is bit more complicated then.

    what info about the roads you get from mapbox?
    you are creating separate mesh for the roads with that info already?
     
  7. andres3341

    andres3341

    Joined:
    Sep 21, 2017
    Posts:
    5
    Hey again! I'll try to investigate how much information do I have with Mapbox, but anyway, I know more or less how my city traffic flows so I can estimate values to try it. To be honest, I didn't try to implement anything yet, I've just searched information about how can I do it. I've found several videos that does something similar:

    (tried to contact him but I'm still waiting to his response)
    (tried to contact him as well, this is where I know I can get information from Mapbox API).

    Thanks for your kind help!
     
  8. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
  9. andres3341

    andres3341

    Joined:
    Sep 21, 2017
    Posts:
    5
    I'll take a look. I've tried to contact him via email and twitter, if he answers back i'll let you know.

    Thanks!