Cube-Elevator

I want to create an elevator with a cube for my 2d game. It should work like the stuff in Mario, … . But it doesn’t work correct. The cube moves up and down, but when my Character is on it, he fells through the cube. He doesn’t moves with the cube. Here is my code:

public List<Vector3> waypointPositions;
    public float speed = 1;
    int currentWaypoint = 0;
    Vector3 targetPositionDelta;
    Vector3 moveDirection = Vector3.zero;
    SpriteController spriteController;

  
    void Start () {
        spriteController = GetComponent<SpriteController>();
    }
 
   
    void Update () {
        Elevator();
        Move();
       
    }
 
    void Elevator() {
     
        Vector3 targetPosition = waypointPositions[currentWaypoint];
        targetPositionDelta = targetPosition - transform.position;
     
        if (targetPositionDelta.sqrMagnitude <= 1) {


         
            currentWaypoint ++;
         
            if(currentWaypoint>=waypointPositions.Count)
                currentWaypoint = 0;
         
         
        }
void Move() {
      
        moveDirection = targetPositionDelta.normalized * speed;
        transform.Translate(moveDirection * Time.deltaTime,Space.World);
    }

It sounds like your cube or your character is missing a collider, or your physics matrix (over in Project Settings → Physics) is ignoring collisions between your cubes and your character :slight_smile: