Search Unity

Problem with colliders on an animated airship i want to be rideable

Discussion in 'Editor & General Support' started by jbarrett98121, Jan 3, 2011.

  1. jbarrett98121

    jbarrett98121

    Joined:
    Jan 3, 2011
    Posts:
    251
    Ok, so i'm a little bit new with unity, and am having a bit of a problem with an object in my scene i am wanting to be a physical collideable object i can jump on to with the player and ride it through it's animation to the end.

    I'ts a large ship, i've imported the models with colliders, it's in the scene, the animation i want is set up for it. so the ship pulls up to the dock, and i can jump on the deck and walk around, but when the ship starts to take off and move (slowly) the player falls through the floor and the ship.

    I thought it might have been because the floor was too thin so i created a box collider that's a bit thicker and aligned it with the floor but the same problem happens still when the ship starts moving. i can stand on it if it's stationary, or moving very subtly though. any help on this? I can provide a link of my demo if need be, thaks!
     
  2. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,160
    Remember all moving objects need a rigidbody attached.
     
  3. jbarrett98121

    jbarrett98121

    Joined:
    Jan 3, 2011
    Posts:
    251
    couldn't get it to work with a rigid body. i turned it on for the floor, set it not to respond to gravity.. and somehow the floor ended up falling through the model.. what am i doing wrong?
     
  4. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,160
    From the Unity documentation about physics:

    "Kinematic Rigidbodies play better with other Rigidbodies. For example if you have an animated platform and you want to place some Rigidbody boxes on top, you should make the platform a Kinematic Rigidbody instead of just a Collider without a Rigidbody"
     
  5. jbarrett98121

    jbarrett98121

    Joined:
    Jan 3, 2011
    Posts:
    251
    ok, so i have the deck of the ship set up as a kinematic rigidbody, and it stays in tact on the ship now, but the player still falls through the ship when it moves. what else could it be?
     
  6. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,160
    Be sure your Player has a (character controller) or (rigidbody and collider) attached. Only one or another. :)
     
  7. jbarrett98121

    jbarrett98121

    Joined:
    Jan 3, 2011
    Posts:
    251
    yes the player has a player controller on. everything else works fine except for the player falling through the ship. any more help on this?
     
  8. jbarrett98121

    jbarrett98121

    Joined:
    Jan 3, 2011
    Posts:
    251
    have tried adding drag also, no effect ...
     
    Last edited: Jan 3, 2011
  9. jbarrett98121

    jbarrett98121

    Joined:
    Jan 3, 2011
    Posts:
    251
    i've tried changing the collision detection on the object, still fall through the floor with continuous dynamic.... object mass is set to 1
     
  10. jbarrett98121

    jbarrett98121

    Joined:
    Jan 3, 2011
    Posts:
    251
    so what i'm noticing is, if i walk onto the deck of the ship the player starts to fall through the floor about a second and a half after standing still or walking around on the floor........... i also noticed if i jump right before i fall, it prevents me from falling through the floor for another second.. ie, so if i keep jumping on the deck while the ship is moving i won't fall through, but if i stand still i fall through in about 1 - 2 seconds.

    i've tried upping the object mass of the deck, to no effect still. what am i doing wrong?


    i have even added this "Don't Go Through Things" script to the player object the the ship object http://www.unifycommunity.com/wiki/index.php?title=DontGoThroughThings

    still does the same thing, player falls through the decks after about a second or two of not moving
     
    Last edited: Jan 3, 2011
  11. jbarrett98121

    jbarrett98121

    Joined:
    Jan 3, 2011
    Posts:
    251
    ok, so i'm pretty sure this has something to do with the player object. the player does not follow the ship object when i stand on top of it, it will land on it, yes, but thei can see the ship moving underneath the player without the player moving. so the player eventually falls through the ship when standing still on it. if i jump the player keeps landing on top of the ship and won't fall through, but will if standing still on it.

    how to i get the player object to "follow" the ship deck and not fall completely through it when the ship moves? i've tried rigid body on the player with all kinds of settings but can't get it to stay with the ship.
     
  12. pat_sommer

    pat_sommer

    Joined:
    Jun 28, 2010
    Posts:
    586
    hey, not sure if you resolved this but i just did a little test because i found this issue interesting, i made the following script that should work fine

    attach this to your ship, and place your character in as the player.

    The distance is judged based on the pivot of your ship, so you can adjust the variables as needed in the inspector, i made the distances as variables so this script can be used for multiple different sized platforms.

    There may be better, more accurate solutions, but this is the quickest one i could whip up for ya! ;)

    if you want a more accurate solution you may set up empty gameObjects as "boundaries" for your ship, and judge your players position based on them, but the same script goes for parenting your player to the ship

    let me know if you have any issues


    Code (csharp):
    1.  
    2.  
    3. var player : Transform;
    4.  
    5. var child_true = 1;
    6. var child_null = 1;
    7.  
    8.  
    9. function Update () {
    10.  
    11. if (Vector3.Distance(player.position,transform.position)<child_true)
    12. {
    13. player.parent = transform;
    14. }
    15. if (Vector3.Distance(player.position,transform.position)>child_null)
    16. {
    17. player.parent = null;
    18. }
    19.  
    20. }
     
  13. lokkna

    lokkna

    Joined:
    Sep 1, 2010
    Posts:
    6
    Thank you so much for this script above. There is so much to read on the subject of scripting that one becomes confused when starting to learn it. For me I am just building a dungeon based on a story I wrote just to give a 3d perspective, and I have to say I am very glad I chose Unity as my engine. These forums help allot, and the people on them love to help others. So that brings me to my question. I have a square object that I flattened out into a platform. This thread, and the script above has finally showed me how to get my first person controller to ride the plat form, but if I move in any direction from the center it stops riding the platform until I get back to the middle. Why? Also I am having problems with the platform NOT pushing the first person controller when standing infront of it. I figured it has to do with something related to the platform since the 1st person controller stops at other walls unless parented to the platform. sigh sorry about the questions, but I am using this script
    function Update () {
    transform.Translate(2*Time.deltaTime,0,0);
    }
    it works great, but how do you make it stop after, lets say 20 feet?
     
  14. lokkna

    lokkna

    Joined:
    Sep 1, 2010
    Posts:
    6
    As much as I hate to admit the simplicity of it... I figured out upping the child true/null ratio added length/width to my platform. I am still having problems though stopping the platform after a certain length/distance, as well as it moving me if I stand in front of it. I tried colliders and rigidbodies on both the platform/first player controller, but I just can't figure out what I am adding, or not adding to make them interact. I am thinking it is a physics thing, but have yet to figure it out.