Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

need help with train chassis physics and/or wheel physics

Discussion in 'Physics' started by IvanInkoustek, Oct 31, 2020.

  1. IvanInkoustek

    IvanInkoustek

    Joined:
    Apr 27, 2019
    Posts:
    11
    Hello, i am quite new to unity and am currently stuck on something. I don't really know how to describe this, but the problem is something like this:

    lets say i want to create a train chassis with rotating wheels/wheel assemblys, how exactly do i achieve that ?
    i tried putting few types of joints on the wheel and a rigidbody component on the "baseplate" but with limited success....
    I had the idea of using wheel colliders, but i dont exactly know how i would achieve those following a track (the track is currently composed of two cubes running paralel to eachother)

    If you have any suggestions that might help, please let me know, any help is grately appreciated.
     
  2. Monique_Dumont

    Monique_Dumont

    Joined:
    Feb 18, 2020
    Posts:
    41
    Hello,
    I don't really understand what you're trying to do. Something like this maybe ?



    What I understand is that you want the metal bar between the wheels to move with them ?

    Or do you just want a train that follows a track ?

    Monique
     
  3. IvanInkoustek

    IvanInkoustek

    Joined:
    Apr 27, 2019
    Posts:
    11
    Right now i am just trying to make a basic chassis that follows the tracks so nothing complicated with pistons on the back wheels.
    I want just want to get the wheel and baseplate interaction functioning - the wheels spin while a baseplate is moving along the track...
    More generally said, i need to figure out how to rotate an object around its "axis" while being "relative" to the parent object (in this case a baseplate).
    This is what my current (very very basic) test rig looks like.
    upload_2020-11-2_14-12-4.png
     
  4. JamesArndt

    JamesArndt

    Unity Technologies

    Joined:
    Dec 1, 2009
    Posts:
    2,912
    This is a really great tutorial for a simplified train system. He offers a Unity package file in the video description as well.

     
  5. IvanInkoustek

    IvanInkoustek

    Joined:
    Apr 27, 2019
    Posts:
    11
    Well, the video was helpful, only problem being that the train featured in said video is made with path following. And while that would most likely be alot easier than trying to do a physical track following contraption (like i'm trying to do), it isn't quite what i was looking for. I am more looking for a way to make a sort of wheel collider that could follow a physical track.
    Anyways, thanks for your suggestion.
     
  6. Monique_Dumont

    Monique_Dumont

    Joined:
    Feb 18, 2020
    Posts:
    41
    Hello,
    So you want a physics based train that follows a track just like in real life ? What more would it bring to you ?
    Also I'm sorry but (someone correct me if I'm wrong) I think that you will have to make your own physics to do something like that.
     
  7. IvanInkoustek

    IvanInkoustek

    Joined:
    Apr 27, 2019
    Posts:
    11
    Correct, but the train is more of an example than an end goal, the question/problem is more about making something like a physical bearing of sorts... The train was just the best example of this i could think of.
     
  8. JamesArndt

    JamesArndt

    Unity Technologies

    Joined:
    Dec 1, 2009
    Posts:
    2,912
    I have looked into doing a train in Unity as well. Having experimented for maybe two months straight. The vast majority of examples you will find are spline path based. I myself wanted to do the exact thing you wanted to and found that no one had implemented something like that. I also used wheel colliders and experimented with dozens of different collision meshes, raycasts, and physics materials. Nothing worked as I wanted it to. This coming from a guy who specializes in wheel physics. I realized that theres no point to creating a system like that unless you are trying to perform a scientific grade physics simulation of train wheel motion and constraints. This level of detail is just not necessary for 95% of train games out there...that is unless the user will be focusing on the train wheels and studying their motion. I figured you were probably just working on a game that didnt require such a detailed wheel physics simulation. All of that wheel motion can be faked as well, so that is a viable solution. As someone else asked what is the benefit of a physics simulation over just controlling transforms and rotations? Physics will be wonky most of the time and difficult to control.

    I actually got a decent train working. I hadn't bothered with wheels at this point as they were pretty trivial. I'd say car wheels are far more complex, with some wheels simultaneously rotating around two axis at once. Train wheels just rotate around their local X axis and that's it. If your spline has enough resolution and the track geometry is modeled with some leeway the carriage wheels will always stay aligned inside of the track rails.

    *Edit - I just saw your response about making a physical bearing of sorts. That might be doable with experimentation with physics materials and high resolution curved meshes. I have managed to push a sphere collider through a straight cylinder, but its a real pain to get one to move through the inside of curved cylinder. In your case it would be more like the interior of a curved rail. Physics materials will allow you to "grease" the bearing ball inside of its rail, but it's the local force that's problematic in Unity's physics implementation.

     
    Last edited: Nov 2, 2020