Search Unity

What am I doing wrong?

Discussion in 'Editor & General Support' started by theave8tor, Sep 24, 2010.

  1. theave8tor

    theave8tor

    Joined:
    Sep 14, 2010
    Posts:
    29
    Hi,

    I am currently making a game where your a tank. It is in third person view. You drive around, and I'm contemplating putting small villages/towns and other AI tanks to shoot at and get shot from. But, as I'm testing the game I find that my tank (currently just a rectangle) likes to go up the side of mountains and doesn't have any physics stopping it. I want it to not be able to do that, and I want it to rotate as it goes up a small slope instead of just staying static and floating up it. Any ideas why this is happening, and any solutions to fix it? Thanks guys/gals!

    Grant Williams
     
  2. appels

    appels

    Joined:
    Jun 25, 2010
    Posts:
    2,687
    are you using a rigidbody or a charactercontroller ?
     
  3. theave8tor

    theave8tor

    Joined:
    Sep 14, 2010
    Posts:
    29
    I am using a character controller.
     
  4. appels

    appels

    Joined:
    Jun 25, 2010
    Posts:
    2,687
    have a look at the charactercontroller and check the slope settings. you can adjust those so it doesn't drive up a wall.
     
  5. theave8tor

    theave8tor

    Joined:
    Sep 14, 2010
    Posts:
    29
    Thanks! Now how do I make it where if it goes up a small slope it rotates on its y axis so it doesn't look like its floating up it? lol
     
  6. iceshaft07

    iceshaft07

    Joined:
    Jul 23, 2010
    Posts:
    293
    Someone posted a plug in to do just that. It might cost money.

    However, the algorithm to do something like that is pretty difficult. You are going to have to find the plane directly underneath the model, figure out its normal, and then rotate the tank based on the normal of the plane.

    I haven't done the above yet, and there might be an easier way with use of the Unity API.
     
  7. laurie

    laurie

    Joined:
    Aug 31, 2009
    Posts:
    638
    It's really not that difficult in the simplest case: raycast down from your model's position; from the resulting RaycastHit, get the normal of the terrain; adjust orientation of your player model (tank) to align with the normal.

    That's a basic approach which may work adequately, depending on your tank model, terrain topology, camera POV, etc. You can get more sophisticated from there depending on how much realism you want -- upto using a full physics model instead of the character controller.