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
2
Question by Ian 1 · Jun 10, 2010 at 10:34 AM · triggeraiwaypoint

OnTriggerEnter/Exit at speed

I use a simple waypoint system with a .next pointer to advance to the next waypoint as my vehicle passes through a waypoint trigger.

I use this with an OnTriggerEnter to trigger when my vehicle passes through a waypoint, which all works fine, however, I don't want my vehicle to be able to stop in a waypoint and reverse out of it or turn around within it and head from where it came, I'd want to be able to track that. This would leave my waypoints list out of sync with where my vehicle is heading and I use the waypoints as triggers for a sequence of events to occur, such as if its the start/finish line -> increase the lap count, if waypoint is waypointN -> open shortcut path etc...

I've tried to make the waypoint trigger area as thin as possible, but then its possible that the OnTriggerX event doesn't fire at all - I also have a small collider/trigger on the front of my vehicle.

I'm sure I could write some convoluted check in the event method(s), but is there any recommended approach to take when working with OnTriggerX with waypoints?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Novodantis 1 · Jun 10, 2010 at 10:56 AM

When you register the trigger collision, store the waypoint object in a variable on the vehicle. Your trigger collision should check to see if the collided object is not the waypoint stored in your variable. This should at the very least ensure you only register a waypoint once (make them big so they definitely register).

As for going backwards, you could then add a subsequent check to see if the waypoint passed is further along the track than the one you stored. Next waypoint if so. And if not, display a large sign saying they are going the wrong way or something? =)

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 Ian 1 · Jun 15, 2010 at 12:41 PM 0
Share

Thanks, I was being too ahead of myself with a next/current/prev waypoints variables to check against, and re-addressed my logic. I used ClosestPointOnBounds() to get the exit point in OnTriggerExit() and tested for this position to be within a region directly after or before my single waypoint variable. Works like a charm.

I also had to make the waypoints sufficiently large so as to not miss a trigger.

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

No one has followed this question yet.

Related Questions

Clearing a destination... 1 Answer

Using box collider to determine if AI should stop help 1 Answer

Guides or Tutorials for a Very Basic Enemy AI? [Unity 5] 1 Answer

Help with a simple AI 2 Answers

How to move to random position? 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