Search Unity

Maglev/monorail type vehicle - suggestions welcome

Discussion in 'Made With Unity' started by pdrummond, Jul 21, 2005.

  1. pdrummond

    pdrummond

    Joined:
    Jun 23, 2005
    Posts:
    185
    Hi everyone,

    I finally got some time to play with Unity again and had a go at creating a maglev/monorail type vehicle for my game. You can view it at:

    http://www.pdrummond.btinternet.co.uk/games/maglevTest.html

    At the moment it's a bit jerky and has a tendency to literally come off the rails. I've linked to a copy of the javascript used, and if anyone can suggest ways to improve it I'd be very happy. I need to work out a way to keep the vehicle on the rail and allow it to move smoothly.

    I've probably made really obvious mistakes, so be gentle!
     
  2. guategeek_legacy

    guategeek_legacy

    Joined:
    Jun 22, 2005
    Posts:
    659
    For me it never is actualy in the track corectly, like it falls on the track but its never stuck in the track's grouves. Jeff
     
  3. pdrummond

    pdrummond

    Joined:
    Jun 23, 2005
    Posts:
    185
    Good point. I've changed it so the vehicle starts on the rails now. I think the problem is that the long rail guide objects get stuck as the vehicle goes round the bend.

    UPDATED

    I've replaced the long side guides with a small 'peg' at each corner. These have a capsule collider which seems to result in smoother movement. Of course, the vehicle still shoots off the rails. Any ideas on how to sort this?
     
  4. pdrummond

    pdrummond

    Joined:
    Jun 23, 2005
    Posts:
    185
    I've updated the script to use the raycast example from the manual to make the vehicle snap to the track. It still has a tendency to come off once speed increases, but I think it's a step in the right direction.

    I need to work out a way to restrict the snap-to-track function so that it only happens when the vehicle is actually on the rail. At the moment if the vehicle comes off it spins around, trying to align itself with the rail instead of falling normally. This brings me back to the collision detection/is vehicle on the ground function I was trying to get working in my jeep example. If someone can show me how to do this I'd really appreciate it.
     
  5. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    One tip is that you don't necessarily need this modelled in separate meshes. Imagine it was one. Then to put a bunch of box colliders everywhere, you could just make blank GameObjects and add a box collider component to them. Then just make those children of the game object with the mesh, and move around and resize them appropriately.

    You might try DynamicsMaterialCombine.Minimum instead of Maximum. Since the docs aren't there on it I can only guess based on my own experience, but Minimum will take the lesser friction of the two colliding objects. (Then you can guess what Average and Multiply might do.) Again, it's speculation but one of the friendly OTEE characters can tell us what's really going on. :)

    When you offset the center of mass it will make your object bottom heavy. This is good in your situation.

    In your FixedUpdate function, you don't ever set the rigidbody velocity to your new one. Whoops. mainBody.rigidbody.velocity = horizontalVelocity; at the end.

    Cheers,
    -Jon
     
  6. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    In general, don't set velocity if you want stability.

    Use AddForce instead (or in this case AddRelativeForce)
    [edit by keli... it said AddRelativeVelocity...]
     
  7. pdrummond

    pdrummond

    Joined:
    Jun 23, 2005
    Posts:
    185
    Brilliant! I'll try this out as soon as I can.
     
  8. pdrummond

    pdrummond

    Joined:
    Jun 23, 2005
    Posts:
    185
    Good idea about using empty Game Objects with colliders. I'll try it out.
     
  9. pikachu

    pikachu

    Joined:
    Aug 6, 2005
    Posts:
    38
    I would use a set of four rings that are invisbile meshes to keep your train on the track. The four rings would then glide along two invisbile tubes that are aligned to your track.

    This should keep it nice and steady.

    Advantage: You can measure the collision force of the rings and the tube. If it gets to high, you destroy the rings and let the car fly off a tangent.

    This actually works. I made a demo on this a long time ago using Blitz3D.

    Kind regards
    Reda Borchardt