Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 gamecreatorTim · Feb 27, 2017 at 11:43 AM · collisionwheeltracksimulatortrain

make a train follow tracks using physics

hello,

I am currently developing an Train Simulator and already got a train with tracks and such. The train uses wheelcolliders for the wheels. Now the problem is that the train drives of the track after while or drives directly off the track on non-straight parts. Now i understand how a real train wheel works but i have trouble recreating that. So my question is how do i make the train wheels stay on the track? I think i need to add a larger piece/wheel to the wheel in the inside of the tracks but if that's the case can someone then tell me how to do that? I do want to use physics so path following is no option.

i hope someone can tell me.

Thanks

Comment
Add comment · Show 7
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 mmciver · Feb 27, 2017 at 04:34 PM 0
Share

I haven't done it myself, but i'd suspect you need to have a pair of wheel colliders, one for the outer part of the wheel that sits on the track, and one for the inner part that sits within it. They should be parent/child relationship, so the two colliders are treated as one. Which is parent I'm not sure about, you will have to play around with it to see if it matters.

avatar image gamecreatorTim mmciver · Feb 27, 2017 at 06:14 PM 0
Share

tried that but when i start driving the inner wheel will just teleport over the rail and it crashes so i dont think this will work either or i am doing it wrong

avatar image mmciver gamecreatorTim · Feb 27, 2017 at 06:21 PM 0
Share

Hmm, sounds like something is set up wrong. When i get some time later today, I'll play around with a test and see if i can get it working.

An alternative that just came to $$anonymous$$d is to use raycasting from one wheel to the opposite track. If it's getting too close or too far, AddForce or $$anonymous$$oveToward to get it back in line. Not quite physics, but probably far more reliable and performance efficient than trying to use colliders, and would still retain realism.

Show more comments
avatar image morvi · May 10, 2018 at 05:13 AM 0
Share

gamecreatorTim

Hello, wanted to know, if you found a solution to stabilize the wheels?

avatar image gamecreatorTim morvi · May 10, 2018 at 01:28 PM 1
Share

Yes I did, you need to use wheel colliders and use sphere colliders between the rails to keep it on the track. But I ended up using splines to make the train follow the track as that is less buggy.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by mmciver · Feb 27, 2017 at 07:37 PM

(from comments)

My mind kept asking myself questions, so I went and played with it.

What you need is a mesh collider. The entire 2-part wheel as a single mesh. You can optionally have a wheel collider on it as well to handle the wheel physics, but the wheel collider is essentially only 2 dimensional, it will only deal with collisions from outside in fore the 'tread of the tire', and will not react to collisions on the face. One challenge with a mesh collider is that you need a high number of faces to the wheel if you don't already. The default Cylinder that I played with has too few faces, and each face on the edge was making it bump along and adds a lot of simulated friction of the wrong type.

But this worked. Here is the test scene i mocked up real quick: https://www.dropbox.com/s/9nf6he4nzizeiui/trainwheeltest.unitypackage?dl=0

I inverted the goal by having cubes as tracks and a few scaled cylinders as the parts of the wheels, and the style is backwards with the large part of the wheel outside the 'track' rather than inside. This is all for the sake of expediency and not having to model the various components first. I tilted the track so I could use gravity rather than having to apply power to the wheels. And I just rotated the cubes by 1 degree each to simulate a curve.

If I was going to turn this into a full solution, I'd have smooth curves, I'd properly weight the wheels and others to prevent them from 'jumping' from hitting the transitions too hard, etc... but i think this shows that it will work for you.

Comment
Add comment · Show 3 · 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 gamecreatorTim · Feb 27, 2017 at 07:46 PM 0
Share

ah, thank you very much!!! i will try to implent it in my train tomorrow and post back the result.

avatar image gamecreatorTim gamecreatorTim · Feb 28, 2017 at 08:30 AM 0
Share

okay, i just implented it in my train but now i need to get it to move. do you know a script that can rotate the wheels so my train can move and i can test? i got 4 wheels on the train btw. And i also need to hingejoint them so they are rotatable

avatar image gamecreatorTim gamecreatorTim · Feb 28, 2017 at 12:44 PM 0
Share

okay, got it to move by using hinge joint but the wheels are very unstable. do you know a better way of moving them?

oh and when the wheels are rotated slowly it is riding fine and i now can drive on non-straight tracks too! thanks you for the example you gave me!

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

7 People are following this question.

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

Related Questions

Advanced collisions: mesh collision? 0 Answers

How to avoid Collisions with seams 1 Answer

How to make a train stay on the rails? 1 Answer

Check if player is on track 1 Answer

Edit WheelCollider's Axis, not the Mesh 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