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 spammenao252 · Jun 26, 2013 at 12:30 PM · c#path

Make an object path across another object

I'm trying to make a cube (cart placeholder) follow along a track:

track

I'm wondering what the best method is to achieve this. A pathing system like Spline Controller will not suffice because I don't want to have to configure the waypoints on the track; it should just follow it. I was thinking of creating the script like so;

  1. Set the target track object

  2. Position the host object in the middle of the track object

  3. Keep raycasting diagonally downwards from the top-front of the cube to see if there's still a track in front of it

  4. Move forward if so

  5. Optionally have the cart/cube reverse direction if the track ends, in case it doesn't loop

  6. Optionally create the path once at script startup rather than dynamically in case the track is static

Would this work, and would it be o.k. performance wise (in other words; is there a better alternative, performance wise)? Also, what do I need to look in to to make the cart/cube turn across curves so it doesn't end up looking silly?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · Jun 26, 2013 at 05:03 PM

The way I see it, to make this work you need two surfaces, one for left and right, and one for up and down. A groove in the track will work, or a simple angle will work...even the edge of the track. Instead of raycasting diagonally downward, I'd place an empty sensor objects in the groove/angle. It would raycast down and to the right. The sensor would adjust itself so that it maintained a set offset to the groove/angle. If you had the object position lag the sensor position, you can use the different positions to define an angle to use as the forward for movement and for the rotation of the cube. You can add a forward raycast to the sensor to sense a stop at the end of the groove/angle. Consider using Collider.Raycast() instead of Physics.Raycast().

Comment
Add comment · Show 6 · 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 spammenao252 · Jun 27, 2013 at 05:58 PM 0
Share

This got me thinking, rather than raycasting at all, would it be possible to 'read' the mesh data and simply create waypoints from that? Then I could create an empty object directly above the left track and have that follow the waypoint system, then all I have to do is joint the cube or whatever I want on top of said empty object and it'll path along.

avatar image robertbu · Jun 28, 2013 at 03:17 AM 0
Share

Reading the mesh is problematic unless you either 1) create the mesh in code, or 2) can guarantee some properties of the mesh. I certainly is possible to do the raycasting solution I outline above in Start() to create the path.

avatar image spammenao252 · Jun 28, 2013 at 01:10 PM 0
Share

But wouldn't that mean I'd have to manually place the sensors?

avatar image robertbu · Jun 28, 2013 at 01:21 PM 0
Share

Vertices don't have to be in any particular order. So it if you were to read the mesh data directly, it could be a difficult, possibly complex, and error prone job to walk the data and generate the path. As for sensors, you'll have to manually place the sensors at the very beginning and also indicate an initial walk direction.

avatar image spammenao252 · Jun 29, 2013 at 01:47 PM 0
Share

How would this work when I only place the sensors at the beginning? If I understand correctly, you suggest a forward raycast on the sensor to see where the track takes a turn so I can automatically place a sensor there, but that raycast might hit the other side of the track, plus the 'automatic' sensors would need to have a way to alter the track-finding-raycast direction because else it would keep raycasting up even after, say, a right turn, when it should start raycasting to the right. Or am I misunderstanding your suggestion completely?

Show more comments
avatar image
0

Answer by killer-zog · Jun 28, 2013 at 01:26 PM

why not use itweenpath system. just modified some line according to what you want and you are good to go.

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 robertbu · Jun 28, 2013 at 04:24 PM 0
Share

He doesn't want to use a path. The whole point of the question is how to walk/generate mesh without specifying a path.

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

16 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 avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

C# nullreferenceexception object reference not set 1 Answer

animation.Play (MissingComponentException: There is no 'Animation' attached to.. 2 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