Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Making a rigidbody follow terrain without tipping over

Discussion in 'Editor & General Support' started by mudloop, Jul 23, 2012.

  1. mudloop

    mudloop

    Joined:
    May 3, 2009
    Posts:
    1,107
    Hi,

    I'm playing around with the idea of making a skiing game of sorts. I'm having some problems with with kind of physics setup I would need for the character. The physics don't have to be super realistic, but it needs to follow the (irregular) terrain, without falling over or spinning out of control. I obviously can't restrict rotations as it has to go along with the shape of the terrain, but when I use just a box collider, it keeps tipping over.

    One solution which I was considering is getting the normal of the polygons underneath the character (either with a raycast or the collision info, not sure yet), and interpolating the rotation based on that, and always interpolate the rotation so he's looking forward, but I'm sure there is an easier way to achieve it - I just can't think of the best way to do it.

    BTW, the terrain is a mesh, not Unity's built-in terrain. Not that it matters much though, just figured I'd mention it.

    Any advice would be highly appreciated.
     
  2. Games-Foundry

    Games-Foundry

    Joined:
    May 19, 2011
    Posts:
    632
    My initial reaction was to suggest using the normals approach you've already outlined. Then locomotion popped into my head...might this allow you to keep the character upright but vary the ankle/foot/ski rotation to match the terrain? Might be worth investigating, although I've not used it properly before. Either that, or directly apply transformations to the appropriate bones. You could also detect the change in angle/height and if over a threshold, apply some bounce to the character's upper legs to make it more realistic? I'm thinking of what a slalom skier looks like when they go over the mounds.

    Just some ideas that may or may not be useful.
     
  3. mudloop

    mudloop

    Joined:
    May 3, 2009
    Posts:
    1,107
    Thanks for the response. This is more of an action game than a physics simulation - though it has a skier that has to follow terrain, his skis don't have to move independantly etc - so Locomotion would probably be overkill. So I went for the normals. So far it's working relatively well, just needs some tweaking.
     
  4. kootenay

    kootenay

    Joined:
    Feb 8, 2011
    Posts:
    116
    If you have still looking for good skiing physics, I have them. :) See my signature, or go on the Asset Store and look for Ski Game Starter Kit - I have a mobile version and browser version... the physics was tricky, and I ended up using wheel colliders to move properly with a terrain mesh that I imported from Google Earth. It's $45 for the full project... let me know if I can help otherwise.
    tx
    Chris