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

Simple Elevator

Discussion in 'Scripting' started by UnityBasic, Apr 25, 2014.

  1. UnityBasic

    UnityBasic

    Joined:
    Aug 9, 2013
    Posts:
    41
    Hi I am new in Unity3d and i was trying to make a simple 2d side scroller with the standard assets.
    So I was trying to make a simple Elevator out of a cube so i was trying to animate the cube that it goes up and down so the side scroller can go up or down. But i noticed that the side scroller falls throw the cube so i tried to script the elevator with vector3.up but the side scroller falls still throw the cube, but an other cube with an rigid body won't fall throw it.
    Does anyone know how to do an simple elevator for the side scroller?

    Thanks for any help.
     
  2. A.Killingbeck

    A.Killingbeck

    Joined:
    Feb 21, 2014
    Posts:
    483
    When the player enters the area of an elevator, parent the player to that elevator object. Then moving the elevator will move the player along with it. When he exits the area, unparent the player.
     
  3. SmokyZebra

    SmokyZebra

    Joined:
    Mar 13, 2014
    Posts:
    139
    How do you parent or unparent objects via script ?
     
  4. A.Killingbeck

    A.Killingbeck

    Joined:
    Feb 21, 2014
    Posts:
    483
    transform.parent = elevator.transform; //Parents the elevator gameobject to the gameobject the script is attached to
    transform.parent = null; //Makes this gameobject have no parent
     
  5. Tiki

    Tiki

    Joined:
    Mar 3, 2013
    Posts:
    299
    PlayerObj = GameObject.Find("Player");

    PlayerObj.transform.parent = GameObject.Find("Elevator");



    unparent :

    PlayerObj.transform.parent = PlayerObj.transform;

    = null also works as noted above.
     
  6. UnityBasic

    UnityBasic

    Joined:
    Aug 9, 2013
    Posts:
    41
    Does it work too if you let a big cube rotate, so that the player doesn't go throw the rotated cube
    Or does it work without pairing too?
    Because objects with rigidbodys attached collides with the elevated so can you attach an rigid body behavior to the player because if i put an normal rigid body to the player, it goes throw the normal cubes too
     
    Last edited: Apr 25, 2014