title: Unity3d charactermotor falling through/sliding off moving platforms
body: <p>Currently implementing moving platforms within my game, I've managed to get the platforms using a switch &amp; cases however when it comes to keeping the player onto the platform either the platform slides under the player and the player falls off after platform has passed or in the case of the platform going up the player falls through the platform</p>
  
  <p>I know unity does a default charactermotor that includes the script in javascript, however I wanted to make a more simple charactermotor that isn't as complicated as the 1 provided by unity.</p>
  
  <p>I've tried adding parenting code such as the 1 below to the moving platform script to no avail:</p>
  
  <pre><code>void triggerOnStay(Collider collider)
  {
      if (collider.tag == "Player")
      {
          collider.transform.parent = transform.parent;
      }
  }
  
  void triggerOnLeave(Collider collider)
  {
      if (collider.tag == "Player")
      {
          collider.transform.parent = null;
      }
  }
  </code></pre>
  
  <p>Wondering if any you lot have any ideas of what I could add or do to allow my charactermotor  be able to stay on the moving platforms whether they go left to right or up &amp; down.</p>
  
  <p>Charactermotor:</p>
  
  <pre><code>public class CharacterMotor2 : MonoBehaviour {
  //Variables
  public Transform respawnPoint1;
  public Transform respawnPoint2;
  public Transform respawnPoint3;
  
  
  public Transform teleporterPoint1;
  public Transform teleporterPoint2;
  
  //public Transform nextLevel;
  public float speed;
  public float jumpSpeed; 
  public float gravity;
  public Vector3 moveDirection = Vector3.zero;
  public float downwardForce;
  public float terminalVelocity;
  public float leftForce;
  public float forwardForce;
  public float airSpeed;
  
  void Update() 
  {
      CharacterController controller = GetComponent&lt;CharacterController&gt;();
      // is the controller on the ground?
      if (controller.isGrounded) 
      {
          //Feed moveDirection with input.
          moveDirection = new Vector3 (Input.GetAxis ("Horizontal"), 0, Input.GetAxis ("Vertical"));
          moveDirection = transform.TransformDirection (moveDirection);
          downwardForce = 0;
          //Multiply it by speed.
          moveDirection *= speed;
  
          //Jumping
          if (Input.GetButton ("Jump"))
          {
              downwardForce -= jumpSpeed;
          }   
      } 
      else 
      {
          if (downwardForce &lt; terminalVelocity)
          {
                  moveDirection *= airSpeed;
                  downwardForce += gravity * Time.deltaTime;
          }
      }
      //Applying gravity to the controller
      moveDirection.y -= downwardForce * Time.deltaTime;
      //Making the character move
      controller.Move(moveDirection * Time.deltaTime);
  }
  void OnTriggerEnter(Collider collider)
  {           
      if (collider.tag == "smallTrampoline") 
      {
          downwardForce *= -1 * collider.gameObject.transform.GetComponent&lt;SmallTrampolineBounce&gt; ().jumpSpeed;
  
      }
      if (collider.tag == "largeTrampoline") 
      {
          downwardForce *= -2 * collider.gameObject.transform.GetComponent&lt;SmallTrampolineBounce&gt; ().jumpSpeed;
      }
      if (collider.tag == "leftTrampoline")   
      {
          downwardForce *= -1 *collider.gameObject.transform.GetComponent&lt;SmallTrampolineBounce&gt; ().jumpSpeed;
      }
      if (collider.tag == "rightTrampoline")  
      {
          downwardForce *= -1 *collider.gameObject.transform.GetComponent&lt;SmallTrampolineBounce&gt; ().jumpSpeed;    
      }
      if (collider.tag == "forwardTrampoline")    
      {
          downwardForce *= -1 *collider.gameObject.transform.GetComponent&lt;SmallTrampolineBounce&gt; ().jumpSpeed;    
      }
      if (collider.tag == "backwardTrampoline")   
      {
          downwardForce *= -1 *collider.gameObject.transform.GetComponent&lt;SmallTrampolineBounce&gt; ().jumpSpeed;    
      }
      if (collider.tag == "Respawn") 
      {
          transform.position = respawnPoint1.position;
      }
      if (collider.tag == "NextRespawn")
      {
          transform.position = respawnPoint2.position;
      }
      if (collider.tag == "FinalRespawn")
      {
          transform.position = respawnPoint3.position;
      }
  
      if (collider.tag == "Teleporter") 
      {
          transform.position = teleporterPoint1.position;
      }
      if (collider.tag == "2ndTeleporter")
      {
          transform.position = teleporterPoint2.position;
      }
  
  
  
  
  
  
      if (collider.tag == "NextLevel") 
      {
          Application.LoadLevel(1);
  
      }
  </code></pre>