Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 anwserman · Apr 15, 2013 at 01:44 PM · collisiontriggerpathvehicle

Objects following a path freeze/lock when hitting each other

I've made a basic traffic system in my app. It involves my vehicles following a simple path, and that's all they do - follow the path. When they hit any certain node, they get shot off onto another path, and that's that. Same applies for spawning and destroying, etc. They don't use physics at all; they're kinematic, path following bots.

The problem I'm facing now is how the cars collide with each other. Each vehicle contains a solid mesh collider ("solidLayer") and in front of each car is a capsule trigger collider ("triggerLayer"). These colliders are in different layers, and ignore any other collision in the game. The vehicle movement script defaults to GO movement, and if OnTriggerStay() is called, the vehicle slows down (brakes).

Everything works fine, but sometimes a vehicle doesn't slow down in time, hitting the car in-front of it, causing them to partially overlap with each other. When this happens, OnTriggerStay() is sometimes called for both vehicles. They're both permanently braking, causing the traffic system to fail (cars behind just queue up in line).

Is there any way I could cheat the system and prevent this from happening, or at least how to elegantly handle this? There's many things I could do - for instance, I could just toss out both cars and return them to the object pool from which they came. However, this would look funky (disappearing cars!) and doesn't look professional. Another way could be to reduce the amount of cars on the road and increase the duration of the spawn points, but that's just trying to make the situation occur less often then dealing with it correctly.

Comment
Add comment · Show 1
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 LyanApps · Apr 15, 2013 at 02:15 PM 0
Share

I like it. It sounds realistic. An accident causing a traffic jam?

1 Reply

· Add your reply
  • Sort: 
avatar image
3

Answer by LyanApps · Apr 15, 2013 at 02:19 PM

You could make both cars aware of each other and use some sort of random time logic.

 Wait Random.Range(0.0f, 3.0f)
 If (time elapsed and other_car not going){
 self going = true
 Continue driving logic
 else wait another Random.Range

You could also give each car a priority upon spawn

 car = Instantiate(car)
 car.setPriority = num_cars++;

Then the higher priority car always goes first.

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 anwserman · Apr 16, 2013 at 08:01 AM 0
Share

I didn't accept this answer because it's not what I did, but it put me on the right path! The vehicles are now aware of each other by sorts, and that they make sure there's enough distance between the two (the vehicles now contain a radius property).

If the target movement distance between the two cars is less than the sum of the radius, the second car doesn't move to that spot! I simply forgot to add a basic logic testing. I assumed the position was always valid to move to. Now I just test it to make sure! Thank you!

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

12 People are following this question.

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

Related Questions

Affect only one clone from multiple clones? 1 Answer

Having problems with 2d collision triggers (javascript) 1 Answer

Collider2D/RigidBody2D not working 1 Answer

Trigger collision with Player won't work 2 Answers

Is Trigger, need help understanding description 1 Answer


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