Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by HolBol · May 27, 2012 at 08:59 PM · directioncarwaypointroads

City traffic Lanes

It's been a while, but I've returned to working on an open city world in unity. I know how to script a car, and have it follow waypoints and so on, what I'm struggling with is how to have the cars in lanes, so opposing sides of the road move in opposite directions.

I know you could have 'sets' of waypoints, but then, how would you make sure the cars moved in random directions? So when they get to junctions, how do they decide whether they are going to go left, or right, or straight on?

My gripe is that games over the years have made it look so simple; from the obvious like Grand Theft Auto, to just being part of the race in games like Need For Speed. Is there just a set of formulae or something that people have used? Who knows.

So yeah, any assistance would be great.

[EDIT] Having figured most of the problem is about the multiple choice decisions the cars need to make at each junction, this is the main problem. Having the cars make different choices already solves the 2-way road problems, so I just need to grasp how to get each car to make a decision and then take the appropriate set of waypoints.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image kolban · May 27, 2012 at 09:15 PM 0
Share

As to your last point, I am pretty sure that a professional game company will not use Unity for their production games. The developers and designers at Grand Theft Auto and Need for Speed have full time dedicated programmers that work for years to achieve the final effects. It is likely that what you see as "looks so simple" is huge amounts of time and research into what is actually "looks so realistic". Under the covers, it may be far from simple.

avatar image HolBol · May 27, 2012 at 09:26 PM 0
Share

No- I never said they use Unity. GTA used RenderWare, and then RAGE for IV. I was not trying to imply that. But to the other half of your comment, yes, that could be true.

3 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by Tasarran · May 31, 2012 at 08:53 PM

Here's a suggestion... This won't solve the problem, but it might help to get outside the box...

Use one set of waypoints, running down the middle of the street.

But instead of having your cars try to line up the center of the car with the waypoint path, have the car line up with a point set just outside the driver's side door.

That way, cars can use either set, and the side of the road they are on will be defined by the way they are going.

Would only work for two lane roads, but I could see the use of a Lane variable that would move the car farther and farther away from the middle...

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
2

Answer by hathol · May 28, 2012 at 01:26 AM

Car AI is quite a challenging thing to do (as is any form of AI actually). The easiest solution that I can think of, is to just check which side of the road your car is on and adjust the steering behaviour accordingly. For checking, you can do something like

 Vector3 v_direction = v_currentWaypoint - v_lastWaypoint; 
 // assume waypoints are Vector3s and set in the middle of the road
 Vector3 v_right = Vector3.Cross(v_direction, Vector3.up);
 if(Vector3.Dot(transform.position - v_lastWaypoint, v_right) > 0)
     // you're on the right side
 else
     // you're on the left side

Alternatively, you could define your navmesh(es) by using one-way waypoints only. So you basically have a set of waypoints for each lane and only allow traversing them in one direction (this can usually be achieved by just not setting the previous waypoint as a neighbour of the following one.

For decisions on crossroads: I would just randomly select any waypoint on the navmesh and let the pathfinding do the rest. If the car reaches the waypoint, just pick another one. Or you could just scrap pathfinding altogether for that and random pick one of the neighbouring waypoints.

Quick Edit: This will only take care of your very basic navigation needs. You will still have to deal with stuff like avoiding obstacles, trafic signals and so on

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image HolBol · May 28, 2012 at 09:13 PM 0
Share

Voting for informity. I can do traffic lights and obsatcle avoiding pretty easily. The changing the steering for each side of the road doesn't sound such a good idea, as each car would keep seem to try to steer into the middle of the road before correcting itself, so that wouldn't look great. The alternative idea could be good. It's not really the sides of roads that's a problem, I guess. because by choosing random paths at junctions, the traffic will already look like it's driving in multiple lanes due to the choices they make. So there's an update to the question.

avatar image
0

Answer by shervpey · Oct 14, 2021 at 12:43 AM

https://github.com/Kink3d/SimpleTraffic

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I change the "forward" direction of my model? 5 Answers

Attempting to add wheel friction to a 2d car 1 Answer

Pointing towards Waypoint 2 Answers

Unity Car tutorial, Wrong way code 0 Answers

I need help figuring out how to make characters follow a custom path that I could make using Unity 3D version2019.1.12f1. 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges